串变蟒蛇

代码示例

13
0

N

#Use f-string
#Example:

x = 2
y = f'This is a string using variable x: {x}'
print(y)

#Output: 
#This is a string using variable x: 2
2
0

N

#Pre 3.6
print('Hi, my name is {name} and my age is {age}'.format(**locals()))

#After 3.6
print('Hi, my name is {name} and my age is {age}')
1
0

N

>>> shepherd = "Martha"
>>> age = 34
>>> # Note f before first quote of string
>>> stuff_in_string = f"Shepherd {shepherd} is {age} years old."
>>> print(stuff_in_string)
Shepherd Martha is 34 years old.
1
0

N

>>> shepherd = "Mary"
>>> age = 32
>>> stuff_in_string = "Shepherd {} is {} years old.".format(shepherd, age)
>>> print(stuff_in_string)
Shepherd Mary is 32 years old.
1
0

N

var str = "ello";
var letter = "h";
str = letter + str;
0
0

N

foo = "bar"
exec(foo + " = 'something else'")
print bar
something else

类似页面

带有示例的类似页面

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................