列印()

王林
發布: 2024-07-26 13:08:54
原創
1046 人瀏覽過

列印()

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

列印() means printing a str, int, flo, etc.

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

print()
登入後複製

eg:

>>>print("hello")
>>>hello
登入後複製

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

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

>>> hello
登入後複製

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
登入後複製

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
登入後複製

Concatenation of strings

We can combine the strings by this.
eg:

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

>>>Parotta salna!
登入後複製

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
登入後複製

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
登入後複製

Printing numbers

It used to print numbers.
eg

>>>print(123545)
>>>123545
登入後複製

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

>>>print(1+3)
>>>4
登入後複製

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

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

>>>['banana','apple','cherry']
登入後複製

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!
登入後複製

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

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

>>>hello 
   everybody
登入後複製

String Multiplication
This is used to Multipling string.
eg:

>>>print("hello"*3)
>>>hellohellohello
登入後複製

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

以上是列印()的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板