Satrlarni birlashtirish
1.words = ["Let", "me", "speak", "from", "my", "heart", "in",
"English"]
2.# ajratuvchi – bo’sh joy
3.sentence = " ".join(words)
4.print(sentence) # Let me speak from my heart in English
5.# ajratuvchi – vertical chiziq
6.sentence = " | ".join(words)
7.print(sentence) # Let | me | speak | from | my | heart |
#in | English
Parametrlarni nomlash
1.text = "Hello, {first_name}.".format(first_name="Tom")
2.print(text) # Hello, Tom.
3.info = "Name: {name}\t Age: {age}".format(name="Bob",
age=23)
4.print(info) # Name: Bob Age: 23
Butun sonlarni formatlash
1.source = "{:d} belgilar"
2.number = 5
3.target = source.format(number)
4.print(target) # 5 belgilar
format() metodisiz formatlash
1.info = "Ism: %s \t Yosh: %d" % ("Tom", 35)
2.print(info) # Ism: Tom Yosh: 35
Satrlar va shart operatorlarining bog’liqligi
a="xsalomx"
b=a[1:-1]
if a[0]=="x" and a[-1]=="x":
print(b)
else:
print("ERROR")
Do'stlaringiz bilan baham: |