Cetak()

王林
Lepaskan: 2024-07-26 13:08:54
asal
1123 orang telah melayarinya

Cetak()

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

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

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

print()
Salin selepas log masuk

eg:

>>>print("hello")
>>>hello
Salin selepas log masuk

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

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

>>> hello
Salin selepas log masuk

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
Salin selepas log masuk

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
Salin selepas log masuk

Concatenation of strings

We can combine the strings by this.
eg:

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

>>>Parotta salna!
Salin selepas log masuk

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
Salin selepas log masuk

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
Salin selepas log masuk

Printing numbers

It used to print numbers.
eg

>>>print(123545)
>>>123545
Salin selepas log masuk

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

>>>print(1+3)
>>>4
Salin selepas log masuk

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

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

>>>['banana','apple','cherry']
Salin selepas log masuk

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!
Salin selepas log masuk

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

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

>>>hello 
   everybody
Salin selepas log masuk

String Multiplication
This is used to Multipling string.
eg:

>>>print("hello"*3)
>>>hellohellohello
Salin selepas log masuk

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

Atas ialah kandungan terperinci Cetak(). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan