|
| 1 | +print("Scalar data types: \n\tintegers, \n\tfloats, \n\tNone (str) and \n\tbool") |
| 2 | + |
| 3 | +# Assigning multiple values to multiple variables |
| 4 | +a, b, c = 5, 3.2, "Hello" |
| 5 | + |
| 6 | +print(a) |
| 7 | +print(b) |
| 8 | +print(c) |
| 9 | + |
| 10 | +# assign the same value to multiple variables at once |
| 11 | +x = y = z = "same" |
| 12 | + |
| 13 | +print(x) |
| 14 | +print(y) |
| 15 | +print(z) |
| 16 | + |
| 17 | +# To write multiple statements in the line use ; |
| 18 | +z = "not same"; print(y); print(z) |
| 19 | + |
| 20 | +# int type |
| 21 | +a = 0b1010 # Binary Literals |
| 22 | +b = 100 # Decimal Literal |
| 23 | +c = 0o310 # Octal Literal |
| 24 | +d = 0x12c # Hexadecimal Literal |
| 25 | + |
| 26 | +# float type |
| 27 | +float_1 = 10.5 |
| 28 | +float_2 = 1.5e2 |
| 29 | + |
| 30 | +# Complex Literal |
| 31 | +x = 3.14j |
| 32 | + |
| 33 | +# Constant should be full uppercase But we can change the value here. |
| 34 | +PI = 13.14 |
| 35 | +PI = PI - 10 |
| 36 | + |
| 37 | +# str type |
| 38 | +strings = "This is Python" |
| 39 | +char = "C" |
| 40 | +string1 = None # similar to null in java which is nothing |
| 41 | + |
| 42 | +# use , to concatenate the strings. similar + in java |
| 43 | +print(a, b, c, d) |
| 44 | +print(float_1, float_2) |
| 45 | +print(x, x.imag, x.real) |
| 46 | +print(PI) |
| 47 | +print(strings, char, string1) |
| 48 | + |
| 49 | +# bool type True or False |
| 50 | +x = (1 == True) |
| 51 | +y = (1 == False) |
| 52 | +a = True + 4 # True is 1 |
| 53 | +b = False + 10 # False is 0 |
| 54 | + |
| 55 | +print("x is", x) |
| 56 | +print("y is", y) |
| 57 | +print("a:", a) |
| 58 | +print("b:", b) |
| 59 | +print("all the below stmt return False") |
| 60 | +print(bool(0)) # False |
| 61 | +print(bool(0.0)) # False |
| 62 | +print(bool("")) # False ? empty string |
| 63 | +print(bool({})) # False ? empty dict |
| 64 | +print(bool([])) # False ? empty list |
| 65 | +print(bool(())) # False ? empty tuple |
| 66 | + |
| 67 | +print("all the below stmt return True") |
| 68 | +# Rest is True |
| 69 | +print(bool("True")) # True |
| 70 | +print(bool("False")) # True |
| 71 | +print(bool("0")) # True |
| 72 | +print(bool(0.01)) # True |
| 73 | +print(bool(-12)) # True |
| 74 | +print(bool(2)) # True |
| 75 | + |
| 76 | +fruits = ["apple", "mango", "orange"] # list |
| 77 | +numbers = (1, 2, 3) # tuple |
| 78 | +alphabets = {'a': 'apple', 'b': 'ball', 'c': 'cat'} # dictionary |
| 79 | +vowels = {'a', 'e', 'i', 'o', 'u'} # set |
| 80 | + |
| 81 | +print(fruits, " is a ", type(fruits)) |
| 82 | +print(numbers, " is a ", type(numbers)) |
| 83 | +print(alphabets, " is a ", type(alphabets)) |
| 84 | +print(vowels, " is a ", type(vowels)) |
| 85 | + |
| 86 | +# type is used to find the type of variable or class name. |
| 87 | +print(type(1)) |
| 88 | +print(type(1.2)) |
| 89 | +print(type("me")) |
| 90 | +print(type(False)) |
0 commit comments