๐ Python Flashcards
To understand certain programming language stuff
What is Python?
It is a programming language known for its simplicity and readability.
Where is Python widely used in?
It is widely used in various fields such as web development, data science, artificial intelligence, and more.
What are the key features in Python? (5)
- Simple and easy-to-read syntax
- Dynamic typing
- Automatic memory management (garbage collection)
- Extensive standard library
- Support for multiple programming paradigms (procedural, object-oriented, functional)
What are the (8) different data types in Python?
- Integers (int)
- Floating-point numbers (float)
- Strings (str)
- Lists (list)
- Tuples (tuple)
- Dictionaries (dict)
- Sets (set)
- Booleans (bool)
define the data type Integers (int)
Whole numbers without any decimal point
eg, -5, 10, 1000
define the data type Floating-point numbers (float)
Numbers with a decimal point or in exponential form
eg. 3.14, -0.001, 2.5e-4
define the data type Strings (str)
Ordered sequence of characters enclosed in single (โโ) or double (โโ) quotes
eg. โHello!โ, โ1234โ
define the data type Lists (list)
- Ordered collection of items, mutable and can contain elements of different data types
- made in square brackets []
eg. [1, 2, 3], [โappleโ, โbananaโ, โorangeโ], [1, โtwoโ, 3.0]
define the data type Tuples (tuple)
- Ordered collection of items, canโt change and can contain elements of different data types.
- made with round brackets ()
eg. (1, 2, 3), (โaโ, โbโ, โcโ), (1, โtwoโ, 3.0)
define the data type Dictionaries (dict)
- Unordered collection of key-value pairs, mutable and indexed by unique keys
- uses curly brackets {}
eg. {โnameโ: โJohnโ, โageโ: 30}, {โfruitโ: โappleโ, โcolorโ: โredโ}
define the data type Set (set)
- Unordered collection of unique elements, mutable and does not allow duplicate values
- Uses curly brackets {}
eg. {1, 2, 3}, {โaโ, โbโ, โcโ}, {True, False}
define the data type Booleans (bool)
Logical data type representing truth values True or False
eg. True, False
when would you use the data type of Integers in your code?
when dealing with whole numbers or counting items that cannot be divided into smaller parts
eg. counting the number of students in a class
when would one use the data type Floating-point numbers (float) in their code?
to deal with quantities that can have fractional parts or require precise calculations
eg. Calculating the average temperature of a city over a period of time.
when would one use the data type Stings (str) in their code?
when working with text data, such as user input, file contents, or messages displayed to the user
eg. Storing a userโs name or a sentence entered by the user
when would one use Lists (list) in their code?
Use lists to store collections of items that need to be ordered and can be modified
eg. Storing a list of tasks to be completed, a list of student grades
When would one use the data type Tuples (tuple) in their code?
to store collections of items that should not be changed after creation, such as fixed data or function arguments
eg. Storing coordinates (latitude, longitude) of a location
when would one use the data type Dictionaries (dict) in their code?
to store data in key-value pairs when quick look-up by a unique identifier (key) is needed
eg. Storing user information using their username as the key,
when would one use the data type Sets (set) in their code?
when dealing with unique elements or performing mathematical set operations like union, intersection, and difference
eg. Storing unique user IDs to see who liked a post
When would one use the data type of Booleans (bool) in their code?
to represent truth values in logical operations or to control the flow of your program based on conditions
eg. Checking if a user is logged in (True or False)
What is a Python module?
- a file containing Python code, typically containing functions, classes, and variables. Modules allow for code organization, reusability, and modularity.
** They can be imported into other Python scripts using the import statement.
What is the difference between โ==โ and โisโ in Python?
The โ==โ operator checks for equality of values, while the โisโ operator checks for identity, i.e., whether two variables refer to the same object in memory.
what are the three conditional statements?
If, elif and else
define these contional statements
used to execute different blocks of code based on specified conditions
eg. Checking if a number is positive, negative, or zero.