1>>> name = "Eric"
2>>> age = 74
3>>> f"Hello, {name}. You are {age}."
4'Hello, Eric. You are 74.'
5
1"""
2
3An f-string stands for 'function-string' it's just used to work with
4strings more appropiately, they do the exact same job as concantenating
5strings but are more efficient and readable.
6
7"""
8# Concantenating strings:
9
10Age = "25"
11
12print("I am "+Age+" years old.")
13
14# Using f strings:
15
16Age = 25
17
18print(f"I am {Age} years old.")
19
20# ^ notice the letter 'f' at the begining of the string.
21# That defines the string as being an f-string.
22
23# A third way of inputting variables into a string is by using
24# .format()
25
26Age = "25"
27
28print("I am {} years old.".format(Age))
29
30# If you had more than one variable:
31
32Age = "25"
33Name = "Jeff"
34
35print("I am {} years old, and my name is {}.".format(Age,Name))
1>>> name = "Eric"
2>>> age = 74
3>>> f"Hello, {name}. You are {age}."
4'Hello, Eric. You are 74.'
1import random
2name = input("What is your name? ") #Gets needed input
3value = int(input(f"Give random value, {name}: ")) # The {name} means it puts the variable name there
4multiplier = random.randint(3, 6)
5print("Now multiplying your value...")
6complete_value = multiplier * value
7print(f"Your value is... {complete_value}") # Same here with complete_value
1# f-strings help in string concatenation
2name = 'Psych4_3.8.3'
3age = 23
4job = 'programmer'
5
6#USING OLD METHOD
7print("I am %s a %t of age %u", %(name, job, age))
8
9# USING F-STRING
10print(f"I am {name} a {job} of age {age}")
11# here you can even see whcih value is inserted in which place....
12# the f means that it is an f string. DONT FORGET IT!!
1import math
2
3print('[[fill]align] | f\'{"text":10}\' | ', f'{"text":10}') # text
4print('[[fill]align] | f\'{"text":>10}\' | ', f'{"text":>10}') # text
5print('[[fill]align] | f\'{"text":^10}\' | ', f'{"text":^10}') # text
6print('[[fill]align] | f\'{"text":#>10}\' | ', f'{"text":#>10}') # ######text
7print('[[fill]align] | f\'{"text":#<10}\' | ', f'{"text":#<10}') # text######
8print('[[fill]align] | f\'{"text":#^10}\' | ', f'{"text":#^10}') # ###text###
9print('[[fill]align] with numbers | f\'{12345:0=10}\' | ', f'{12345:0=10}') # 0000012345
10print('[[fill]align] with numbers | f\'{-12345:0=10}\' | ', f'{-12345:0=10}') # -000012345
11print('[[fill]align] with numbers | f\'{12345:010}\' | ', f'{12345:010}') # 0000012345
12print('[[fill]align] with numbers | f\'{-12345:010}\' | ', f'{-12345:010}') # -000012345
13print('[.precision] | f\'{math.pi:.2f}\' | ', f'{math.pi:.2f}') # 3.14
14print('[grouping_option] | f\'{1000000:,.2f}\' | ', f'{1000000:,.2f}') # 1,000,000.00
15print('[grouping_option] | f\'{1000000:_.2f}\' | ', f'{1000000:_.2f}') # 1_000_000.00
16print('[sign] (+/-) | f\'{12345:+}\' | ', f'{12345:+}') # +12345
17print('[sign] (+/-) | f\'{-12345:+}\' | ', f'{-12345:+}') # -12345
18print('[sign] (+/-) | f\'{12345:+10}\' | ', f'{12345:+10}') # +12345
19print('[sign] (+/-) | f\'{-12345:+10}\' | ', f'{-12345:+10}') # -12345
20print('[sign] (+/-) | f\'{12345:+010}\' | ', f'{12345:+010}') # +000012345
21print('[sign] (+/-) | f\'{-12345:+010}\' | ', f'{-12345:+010}') # -000012345
22print('[b] (binary) | f\'{10:b}\' | ', f'{10:b}') # 1010
23print('[o] (octal) | f\'{10:o}\' | ', f'{10:o}') # 12
24print('[x] (hexadecimal) | f\'{100:x}\' | ', f'{100:x}') # 64
25print('[#b] (with notation base) | f\'{10:#b}\' | ', f'{10:#b}') # 0b1010
26print('[#0] (with notation base) | f\'{10:#o}\' | ', f'{10:#o}') # 0o12
27print('[#x] (with notation base) | f\'{10:#x}\' | ', f'{10:#x}') # 0xa
28print('[e] (scientific notation) | f\'{345600000000:e}\' | ', f'{345600000000:e}') # 3.456000e+11
29print('[c] (character type) | f\'{65:c}\' | ', f'{65:c}') # A
30print('percentage (multiply by 100) | f\'{0.25:0%}\' | ', f'{0.25:0%}') # 25.000000%
31print('percentage (multiply by 100) | f\'{0.25:.0%}\' | ', f'{0.25:.0%}') # 25%
32