Drucken()

王林
Freigeben: 2024-07-26 13:08:54
Original
840 Leute haben es durchsucht

Drucken()

hi, everybody
today I gone to explain which I learnt.

Drucken() means printing a str, int, flo, etc.

Printing a String
when we want to print a string can use this syntax:
syntax:

print()
Nach dem Login kopieren

eg:

>>>print("hello")
>>>hello
Nach dem Login kopieren

Printing a variables
When we want to print a variables we can use this syntax
eg:

>>>name="hello" 
>>>print(name)

>>> hello
Nach dem Login kopieren

Printing into multiple items
You can print multiple items by separating them with commas.
eg:

>>>age="45"
>>>city="chennai"
>>>name="kavin"
>>>print("Name:",name,"Age:",age,"City:",city")

>>>Name: kavin Age: 45 City: chennai
Nach dem Login kopieren

Formatting with f-strings
An f-string is a way to format strings in Python. You can insert variables directly into the string by prefixing it with an f and using curly braces {} around the variables.
eg:

>>>age="45"
>>>city="chennai"
>>>name="kavin"
>>>print("Name:{name},Age:{age},City:{city}")

>>>Name: kavin Age: 45 City: chennai
Nach dem Login kopieren

Concatenation of strings

We can combine the strings by this.
eg:

>>>main_dish="Parotta"
>>>side_dish="salna"
>>>print(main_dish+""+side_dish+"!")

>>>Parotta salna!
Nach dem Login kopieren

Escape sequencenes
Escape sequences allow you to include special characters in a string. For example, \n adds a new line.
eg:

>>>print("hi\nhello\nfriends")
>>>hi
   hello
   friends
Nach dem Login kopieren

Raw(r) strings
Raw stings are strings which type only which is give in the input.
eg:

>>> print(r"C:users\\name\\tag")
>>> C:users\name\tag
Nach dem Login kopieren

Printing numbers

It used to print numbers.
eg

>>>print(123545)
>>>123545
Nach dem Login kopieren

Printing the results of the expressions
This is used to find the value of a expression.
eg;

>>>print(1+3)
>>>4
Nach dem Login kopieren

Printing lists and dictionaries
We can the entire lists and dictionaries.
eg:

>>>fruits["banana","apple","cherry"]
>>>print(fruits)

>>>['banana','apple','cherry']
Nach dem Login kopieren

using sep and end Parameters
We can use this to separate(sep) and end(end) with this parameters.
eg:

>>>print("hello","world",sep="-",end="!")
>>>hello-world!
Nach dem Login kopieren

Triple Quotes
We can use this for print as a same.
eg:

>>>print("""
hello 
everybody
""")

>>>hello 
   everybody
Nach dem Login kopieren

String Multiplication
This is used to Multipling string.
eg:

>>>print("hello"*3)
>>>hellohellohello
Nach dem Login kopieren

This is learnt in the class of python print() class which is I leant by seeing Parotta Salna python class of Day-2

Das obige ist der detaillierte Inhalt vonDrucken(). Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Quelle:dev.to
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Artikel des Autors
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!