This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reassigning variable with a different data type | |
x = 10 | |
print(x) # Output: 10 | |
print(type(x)) # Output: <class 'int'> | |
x = str(x) | |
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_var = 10 | |
some_var = some_var + 5 | |
print(some_var) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_dict = {"name": "John", "age": 30, "city": "New York"} | |
print(my_dict) # {'name': 'John', 'age': 30, 'city': 'New York'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_tuple = (1, 2, 3, 4, 5) # a tuple of integers | |
print(my_tuple) # (1, 2, 3, 4, 5) | |
my_tuple2 = ('apple', 'banana', 'cherry') # a tuple of strings | |
print(my_tuple2) # ('apple', 'banana', 'cherry') | |
my_tuple3 = (1, 'apple', True, 3.14) # a tuple with mixed data types | |
print(my_tuple3) # (1, 'apple', True, 3.14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_list = ['apple', 'banana', 'cherry'] | |
print(my_list[0]) # 'apple' | |
print(my_list[-1]) # 'cherry' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_byte = b'Hello' | |
my_string = my_byte.decode('utf-8') # converts bytes to a string using UTF-8 encoding | |
print(my_string) # 'Hello' | |
new_byte = my_string.encode('utf-8') # converts the string back to bytes using UTF-8 encoding | |
print(new_byte) # b'Hello' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Boolean | |
is_true = True | |
is_false = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Strings | |
name = "John Doe" | |
message = 'Hello, World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 42 # integer | |
y = 3.14 # float | |
z = 1 + 2j # complex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example variable declarations | |
x = 22 | |
name = "John Doe" | |
is_valid = True | |
print(x,name,is_valid) |
NewerOlder