1.1 Review of Python Basics Flashcards

1
Q

What is Python?

A

a popular programming language.

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

What is Python?

A

It was created in 1991 by Guido van Rossum.

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

Python is used for:

A
  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What can Python do?

A

*can be used on a server to create web applications.

*can be used alongside software to create workflows.

*can connect to database systems. It can also read and modify files.

*can be used to handle big data and perform complex mathematics.

*can be used for rapid prototyping, or for production-ready software development.

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

Why Python?

A

*Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).

*Python has a simple syntax similar to the English language.

*Python has syntax that allows developers to write programs with fewer lines than some other programming languages.

*Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.

*Python can be treated in a procedural way, an object-orientated way or a functional way.

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

Whenever you are done in the python command line, you can simply type _____ to quit the python command line.

A

exit()

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

*very important

*indicate a block of code.

A

Python Indentations

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

Python will give you an error if you skip the ________:

A

indentation

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

Python has _________ capability for the purpose of in-code documentation.

A

commenting

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

________ start with a #, and Python will render the rest of the line as a comment

A

Comments

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

Python also has extended documentation capability, called _________.

A

docstrings

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

can be one line, or multiline

A

Docstrings

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

Python uses ______ ______ at the beginning and end of the docstring

A

triple quotes

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

Unlike other programming languages, Python has no command for declaring a variable.

A

Creating Variables

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

*A ________ is created the moment you first assign a value to it.

A

variable

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

_________ do not need to be declared with any particular type and can even change type after they have been set.

A

Variables

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

Rules for Python variables:

A

*A variable name must start with a letter or the underscore character

*A variable name cannot start with a number

*A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

*Variable names are case-sensitive (age, Age and AGE are three different variables)

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

Three numeric types in Python:

A
  • int
  • float
  • complex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

To verify the type of any object in Python, use the _____ function

A

type()

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

is a whole number, positive or negative, without decimals, of unlimited length.

A

int or integer

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

is a number, positive or negative, containing one or more decimals.

A

float

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

Float can also be scientific numbers with an “__” to indicate the power of 10.

A

e

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

_________ numbers are written with a “j” as the imaginary part

A

complex

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

Specify a Variable Type

A

*There may be times when you want to specify a type on to a variable.

*This can be done with casting.

*Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Fixed values such as numbers, letters, and strings are called "______" - because their value does not change
constants
26
_______ constants are as you expect
Numeric
27
_______ constants use single-quotes (') or double-quotes(")
String
28
A _______is a named place in the memory where a programmer can store data and later retrieve the data using the variable “name”
variable
29
You can not use ________ words as variable names / identifiers
reserved
30
We assign a value to a variable using the _________ __________
assignment statement (=)
31
consists of an expression on the right hand side and a variable to store the result
assignment statement (=)
32
//
integer division
33
**
Power
34
%
Remainder
35
Operator Precedence Rules
Highest precedence rule to lowest precedence rule - Parenthesis are always respected - Exponentiation (raise to a power) - Multiplication, Division, and Remainder - Addition and Subtraction - Left to right
36
When you perform an operation where one operand is an integer and the other operand is a floating point the result is a _________
floating point
37
used to output variables
print() statement
38
To combine both text and a variable, Python uses the __ character:
+
39
For numbers, the + character works as a _________ _________:
mathematical operator
40
We can instruct Python to pause and read data from the user using the ______ function
input
41
The input function returns a ______
string
42
three basic types of control structures:
- sequential - selection - repetition
43
default mode. ________ execution of code statements (one line after another) -- like following a recipe
Sequential
44
used for decisions, branching -- choosing between 2 or more alternative paths.
Selection
45
In Python, these are the types of selection statements:
if if-else if-elif-else
46
used for looping, i.e. repeating a piece of code multiple times in a row.
Repetition
47
Recall that Python has a type called boolean, which can take two possible values, ____ and _____
True, False
48
An expression that evaluates to a true/false value is called a ________ ___________
Boolean expression
49
The __ statement contains a logical expression using which data is compared and a decision is made based on the result of the comparison.
if
50
An ____ _________ can be combined with an if statement.
else statement
51
An ____ statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.
else
52
The ____ _________ allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.
elif statement
53
You can use one if or else if statement inside another if or else if statement(s).
nested if statement
54
Python has two primitive loop commands:
- while loop - for loop
55
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
while loop
56
A loop becomes ______ loop if a condition never becomes FALSE.
infinite
57
If the else statement is used with a ___ loop, the else statement is executed when the loop has exhausted iterating the list.
for
58
If the else statement is used with a ____ loop, the else statement is executed when the condition becomes false.
while
59
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
for loop
60
It has the ability to iterate over the items of any sequence, such as a list or a string.
for loop
61
Python programming language allows to use one loop inside another loop.
Nested loop
62
is a block of organized, reusable code that is used to perform a single, related action.
function
63
provide better modularity for your application and a high degree of code reusing.
function
64
Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are called ___________ ________
user-defined functions
65
Function blocks begin with the keyword ___ followed by the function name and parentheses ( ( )
def
66
The first statement of a function can be an optional statement
documentation string of the function or docstring
67
The statement _______ [expression] exits a function, optionally passing back an expression to the caller.
return
68
types of formal arguments:
- Required arguments - Keyword arguments - Default arguments - Variable-length arguments
69
the arguments passed to a function in correct positional order.
required arguments
70
_______ __________are related to the function calls. When you use _______ arguments in a function call, the caller identifies the arguments by the parameter name.
Keyword arguments, Keyword
71
is an argument that assumes a default value if a value is not provided in the function call for that argument.
Default arguments
72
You may need to process a function for more arguments than you specified while defining the function. are not named in the function definition, unlike required and default arguments.
Variable-length arguments
73
These functions are called _________ _________ because they are not declared in the standard manner by using the def keyword.
Anonymous Functions
74
______ keywoard to create small anonymous functions.
lambda
75
can take any number of arguments but return just one value in the form of an expression. They cannot contain commands or multiple expressions.
Lambda forms
76
cannot be a direct call to print because lambda requires an expression
anonymous function
77
have their own local namespace and cannot access variables other than those in their parameter list and those in the global namespace.
Lambda functions
78
two basic scopes of variables in Python
- Global variables - Local variables
79
can be accessed only inside the function in which they are declared
local variables
80
can be accessed throughout the program body by all functions
global variables