Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Web - L03(statement)

Snippet info

Language

Python

Visibility

public

Author

victormakwaitat

Created

2025-02-05T07:54:38.487108Z

Updated

2025-02-05T09:33:40.557569Z

x = 10
if x > 1: # x> 1 return True or Flase, x>1 is expression
    print("x is greater than 1")
else:
    print("x is less than 1")
print(1 == True) # 1 is True, 0 is False
print(0 == True)

x = (None or [] or {} or False) # falsy value
#print(x)
x = (None or [] or 1 or {} or False) # trusy value return 1, if 0, return false
#print(x)
x = (True and {"name":"john"} and [1] and False)
#print(x)
x = (True and [] and {"name":"john"} and [1] and False)
print(x) # print []

def z(x):
    print("I am from function z.",x)
x = 10
if print("I am at if statement") or z(x) or x > 1: # x > 1 return True or False
    print("x is greater than 1")
else:
    print("x is less than 1")
    
default_city = "TST"
city = ''
city = (city or print("please input city") or default_city)
print(city) # print "please input city" and "TST" because city var. is False

default_city = "TST"
city = 'kn'
city = (city or print("please input city") or default_city)
print(city) # print 'kn'

value = ((1,) and [1] and 1 and 1.0)
print(value) # print "1.0"

x = 5
value = (x == 5 and x < 10) # == and < are logic operators. So, the result returns True or False
print(value) # print "True"

x = 10
if x > 125:
    print("x is larger than 125")
elif x > 10:
    print("x is larger than 10")
else:
    print("x is less than or equal to 10")
    
if (-1):
    print("x is larger than 125")
elif (-1):
    print("x is larger than 10")
else:
    print("x is less than or equal to 10")
INFO