인쇄()

王林
풀어 주다: 2024-07-26 13:08:54
원래의
841명이 탐색했습니다.

인쇄()

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으로 문의하세요.
저자별 최신 기사
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!