“F Строка в Python” Ответ

F Строки

var = 1
print(f'number {var}')
A DG

F Строка

# f string
name = 'John'
age = 43
st = f"Hello my name is {name}, I am {age} years old."
print(st) 
Impossible Impala

F Строка в Python

# Ques.1
num = int(input("Enter your number: "))

for i in range(1, 11):
    # print(str(num) + " × " + str(i) + " = " + str(i*num))
    # you can't add variables
    
    print(f"{num} × {i} = {num*i}")
    # you can add variables
Xinov10

Что использует F в Python?

The f or F in front of strings tells Python to look at the values inside {} and substitute them with the values of the variables if exist.
Example:
agent = 'James Bond'
num = 9

# old ways
print('{0} has {1} number '.format(agent, num))

# f-strings way
print(f'{agent} has {num} number')

OUTPUT:
James Bond has 9 number
Fancy Ferret

Python F Строки

'''
In python, rather than adding pieces of string together, you can use
f-strings to insert variables into strings. This makes your code much
more easier to read.
'''

# OLD - WITHOUT F-STRINGS
name = 'Bob'
age = 12
print('This is ' + name + ', he is ' + age + ' years old.')

# NEW - WITH F-STRINGS
print(f'This is {name}, he is {age} years old') # Note the f in front
Ninja Penguin

Ответы похожие на “F Строка в Python”

Вопросы похожие на “F Строка в Python”

Больше похожих ответов на “F Строка в Python” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования