Conditionals is about decision making
# Example conditionals
## Some new tricks, one line
print ("foo" if True else "bar")
a = 3 if i == 4 else 99
i = 3
if i in [ 1,2,3 ]:
print ( i )
x, y = 2, 9
if ( x > y ):
z = x - y
elif:
z = x + y
else:
z = 0
def function_p ( *args ):
numargs = len ( args )
if numargs < 1: raise TypeError ( "requires at least one argument" )
elif numargs == 1: pass
else: raise TypeError ( "Too many arguments" )
## Nah, Python does not have switch-case statement like Java
## Python short-circuit logical AND
## Python does not have logical "&&"
if True and True:
print ( "It is true!" )
a = ord('a')
b = 15
c = 0xf
d = 0b1111
print (a)
print (b)
print (c)
print (d)
print (hex(b))
print (bin(b))
No comments:
Post a Comment