string

Create a string and put it in single, double or triple quotation marks. The quotation marks used in the string must match. The text between the two triple quotation marks is regarded as the content of the string. Strings specified in quotes or double quotes must be on one logical line.

1. Strings are stored in a sequence of characters, which are indexed using integers, starting from zero and using the s[i] index:

a='hsfdjkfhkfdkfd'
d=a[2]
print(d)

Output result:
 f

2. To extract a substring, you can use the form of slice s[i:j]

3. You can use + to concatenate two strings

4. Use str(), repr() and format() to convert non-strings to strings

a=4.3
b=str(a)
c=repr(a)
d =format(a, ' 0.4f ' ) #reserve 4 digits after the decimal point 
print (b,c,d)
Output result:
4.3 4.3 4.3000

 



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324685848&siteId=291194637
Recommended