Python freecodeacmp Flashcards

1
Q

A variable is

A

a name that references or points to an object. You can declare a variable by using the assignment operator = to assign a value like this:

variable_name = value

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

Variables can store

A

values of different data types.

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

Strings are

A

sequences of characters enclosed by single or double quotes, but you cannot start a string with a single quote and end it with a double quote or vice versa

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

print()

A

built-in function to print the output of your code on the terminal

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

Each string character can be referenced by

A

a numerical index. The index count starts at zero. So the first character of a string has an index of 0.

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

The last character has an index of

A

-1

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

the second to last has index of

A

-2

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

You can access the number of characters in a string with

A

the built-in len() function.

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

type() is

A

built-in function which returns the data type of a variable.

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

Key aspects of variable naming in Python are:

A

1-Some words are reserved keywords (e.g. for, while, True). They have a special meaning in Python, so you cannot use them for variable names.

2-Variable names cannot start with a number, and they can only contain alpha-numeric characters or underscores.

3-Variable names are case sensitive, i.e. my_var is different to my_Var and MY_VAR.

4-Finally, it is a common convention to write variable names using snake_case, where each space is replaced by an underscore character and the words are written in lowercase letters.

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

find() function:

A

built-in function used to locate the character, find() returns the index of the matching character inside the string. If the character is not found, it returns -1

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

lower() function.

A

transform a string into its lowercase

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

for i in

A

how to write it

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

indentation

A

Python relies on indentation to indicate blocks of code. A colon at the end of a line is a signal that a new indented block of code will follow.

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

An argument is

A

an object or an expression passed to a function — between the parentheses — when it is called. The print function can take multiple arguments, separated by a comma.

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

Strings are immutable, which means

A

they cannot be changed once created.

17
Q

You can obtain the same effect of a = a + b by using

A

the addition assignment operator:

a += b

18
Q

Comparison operators

A

allow you to compare two objects based on their values. You can use a comparison operator by placing it between the objects you want to compare. They return a Boolean value — namely True or False — depending on the truthfulness of the expression.

Python has the following comparison operators:

Operator Meaning
== Equal
!= Not equal
> Greater than
< Less than
≥ Greater than or equal to
≤ Less than or equal to

19
Q

a conditional if statement.

A

This is composed of the if keyword, a condition, and a colon :.

if <condition>:
<code></code></condition>

A conditional statement can also have an else clause. This clause can be added to the end of an if statement to execute alternative code if the condition is false:

if condition:
<code>
else:
<code></code></code>

20
Q

A function is

A

essentially a reusable block of code. You have already met some built-in functions, like print(), find() and len(). But you can also define custom functions like this:

def function_name():
<code>
A function declaration starts with the def keyword followed by the function name — a valid variable name — and a pair of parentheses. The declaration ends with a colon.</code>

To execute, a function need to be called like this:

function_name()

Now you should see the output again. Although this approach works, it doesn’t significantly enhance the code’s reusability. Repeatedly calling your function will result in the same outcome. However, functions can be declared with parameters to introduce versatility and customization:

21
Q

Parameters are

A

variables that you can use inside your function. A function can be declared with different number of parameters. In the example above, param_1 and param_2 are parameters.

def function_name(param_1, param_2):
<code></code>

22
Q

Vigenère cipher

A

where the offset for each letter is determined by another text, called the key.