๐Ÿ Python Flashcards

To understand certain programming language stuff

1
Q

What is Python?

A

It is a programming language known for its simplicity and readability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where is Python widely used in?

A

It is widely used in various fields such as web development, data science, artificial intelligence, and more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the key features in Python? (5)

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the (8) different data types in Python?

A
  1. Integers (int)
  2. Floating-point numbers (float)
  3. Strings (str)
  4. Lists (list)
  5. Tuples (tuple)
  6. Dictionaries (dict)
  7. Sets (set)
  8. Booleans (bool)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

define the data type Integers (int)

A

Whole numbers without any decimal point

eg, -5, 10, 1000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

define the data type Floating-point numbers (float)

A

Numbers with a decimal point or in exponential form

eg. 3.14, -0.001, 2.5e-4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

define the data type Strings (str)

A

Ordered sequence of characters enclosed in single (โ€˜โ€™) or double (โ€œโ€) quotes

eg. โ€œHello!โ€, โ€œ1234โ€

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

define the data type Lists (list)

A
  • 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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

define the data type Tuples (tuple)

A
  • 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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

define the data type Dictionaries (dict)

A
  • Unordered collection of key-value pairs, mutable and indexed by unique keys
  • uses curly brackets {}

eg. {โ€˜nameโ€™: โ€˜Johnโ€™, โ€˜ageโ€™: 30}, {โ€˜fruitโ€™: โ€˜appleโ€™, โ€˜colorโ€™: โ€˜redโ€™}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

define the data type Set (set)

A
  • Unordered collection of unique elements, mutable and does not allow duplicate values
  • Uses curly brackets {}

eg. {1, 2, 3}, {โ€˜aโ€™, โ€˜bโ€™, โ€˜cโ€™}, {True, False}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

define the data type Booleans (bool)

A

Logical data type representing truth values True or False

eg. True, False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

when would you use the data type of Integers in your code?

A

when dealing with whole numbers or counting items that cannot be divided into smaller parts

eg. counting the number of students in a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

when would one use the data type Floating-point numbers (float) in their code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

when would one use the data type Stings (str) in their code?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

when would one use Lists (list) in their code?

A

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

17
Q

When would one use the data type Tuples (tuple) in their code?

A

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

18
Q

when would one use the data type Dictionaries (dict) in their code?

A

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,

19
Q

when would one use the data type Sets (set) in their code?

A

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

20
Q

When would one use the data type of Booleans (bool) in their code?

A

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)

21
Q

What is a Python module?

A
  • 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.
22
Q

What is the difference between โ€˜==โ€™ and โ€˜isโ€™ in Python?

A

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.

23
Q

what are the three conditional statements?

A

If, elif and else

24
Q

define these contional statements

A

used to execute different blocks of code based on specified conditions

eg. Checking if a number is positive, negative, or zero.

25
what are the two types of loops?
1. For loop 2. While Loop
26
why would one use loops?
to execute a block of code repeatedly until a certain condition is met
27
what does a 'for' loop do?
* Iterating over elements in a list, tuple, or string. * Performing a specific number of iterations known beforehand.
28
what does a 'while' loop do?
* Iterating until a certain condition is met, such as reaching a specific value. * Iterating based on user input or external conditions where the number of iterations is uncertain.
29
what does it mean to iterate? (define the verb 'itering')
he process of going through each item in a collection (like a list, tuple, or string) and performing some action with each item ## Footnote eg. you have a list of numbers [1, 2, 3, 4, 5], iterating over this list means going through each number one by one and performing some operation, such as printing the number or adding it to a sum.
30
what are functions and why use them?
* to group reusable code and perform specific tasks. * Functions can take input parameters and return output values. | eg. Defining a function to calculate the factorial of a number.