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
# assign 4 to the variable x | |
x = 4 |
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
// C code | |
// C is a statically-typed language | |
int x = 4; |
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
# Python code | |
# Python is a dynamically-typed language | |
x = 4 |
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 = 1 # x is an integer | |
x = 'hello' # now x is a string | |
x = [1, 2, 3] # now x is a list |
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 = 4.5 | |
x.is_integer() | |
# False | |
x = 4.0 | |
x.is_integer() | |
# True | |
type(x.is_integer) | |
# <class 'builtin_function_or_method'> |
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
# Numbers | |
integer_number = 23 | |
floating_point_number = 23.5 | |
complex_number = 2 + 3.8j | |
# Boolean | |
boolean_value = True | |
# String Literal | |
string_literal = 'This is a text.' |
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
isinstance('Hello', (float, int, str, list, dict, tuple)) | |
# True |
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
# Primitive Data Structures (Types) | |
# All Primitive Data Types are Immutable Objects | |
int_ = 5 # int - Immutable Object | |
float_ = 5.25 # float - Immutable Object | |
complex_ = 2 + 7.25j # complex - Immutable Object | |
str_ = 'This is a text' # str - Immutable Object | |
bool_ = False # bool - Immutable Object | |
type(int_) # int - Integer Numbers | |
# <class 'int'> |
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
# Number - Integer, Float, Complex | |
# Integer | |
Integer in Python are numbers without decimal e.g 20 | |
# A different data type can be converted to an integer | |
# Integer conversion is done with the int() function | |
book_price = 20 | |
print(book_price) | |
# 20 | |
book_price = '30' | |
print(int(book_price)) |
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
z = 2 + 17.6j | |
print(z) | |
# (2 + 17.6j) | |
print(z.real) | |
# 2.0 | |
print(z.imag) | |
# 17.6 | |
print(z.conjugate()) | |
# (2-17.6j) |
OlderNewer