Jul 9, 2024
hi = "hello there"+ operator.
hi + name results in hello thereAna (no space added automatically).hi + " " + name results in hello there Ana.* operator to repeat strings.
hi * 3 results in hello therehello therehello there., insert spaces between items automatically.+ concatenates items without spaces; all items must be strings.x = 1
print("My fav num is", x) # results in spaces
print("My fav num is" + str(x)) # no spaces
input(), prompts user and reads input as a string.text = input("Type anything: ")
print(5 * text)
num = int(input("Give a number: "))>, <, >=, <=, ==, != for integers, floats, strings.
if i == j, if a != b.not, and, or for booleans.
if not a
if a and b
if a or b
if condition:
# code block
if condition:
# code block
else:
# another code block
if condition1:
# code block
elif condition2:
# another code block
else:
# fallback code block
while condition:
# code block
while user_input == "right":
user_input = input("Go left or right: ")
for variable in range(stop):
# code block
for i in range(5):
print(i)
range(stop): 0 to stop-1.range(start, stop): start to stop-1.range(start, stop, step): start to stop-1 with increments of step.while condition:
# code block
if break_condition:
break
break statements.