Python Flashcards

1
Q

Python is used for ______

A

web development (server-side),
software development,
system scripting

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

Indentation refers to the _____ at the beginning of a code line.

A

spaces
the indentation in Python is very important.

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

The number of spaces is up to you as a programmer, the most common use is ___, but it has to be at least one.

A

four

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

You have to use the ________ in the same block of code, otherwise Python will give you an error:

A

same number of spaces

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

In Python, variables are created when you ______

A

assign a value to it.

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

Comments start with a ___

A

#

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

Python does not really have a syntax for _______ comments.

A

multiline

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

You can use ________ string as multiline comment

A

multiline string (triple quotes)
“ “ “This
is multiline comment “ “ “

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

You can get the data type of a variable with the____function.

A

type()
y = “John”
print(type(y))

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

Variable names are _______

A

case-sensitive. (‘a’ is different than “A”)

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

A variable name must start with a __________

A

letter or the underscore character

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

A variable name cannot start with a _______

A

number

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

A variable name can only contain ____________

A

alpha-numeric characters and underscores

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

Multi Words Variable Names

Variable names with more than one word can be difficult to read.

There are several techniques you can use to make them more readable:

A

Camel Case (Each word, except the first, starts with a capital letter:) - myVariableName = “John”

Pascal Case (Each word starts with a capital letter:) -MyVariableName = “John”

Snake Case (Each word is separated by an underscore character:) - my_variable_name = “John”

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

Python _____ function is often used to output variables.

A

print()

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

The best way to output multiple variables in the print() function is to separate them with ____ which even support different data types:

A

commas
x = 5 y = “John”
print(x, y)

5 John

17
Q

Insert the correct keyword to make the variable x belong to the global scope.

def myfunc():
________ x
x = “fantastic”

A

global

18
Q

Built-in Data Types

A

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType

19
Q

You can get the data type of any object by using the _____function:

A

type()
print(type(x))
<class ‘list’>

20
Q

Data type of below,
x = [“apple”, “banana”, “cherry”] - _________
x = (“apple”, “banana”, “cherry”) - ____________
x = {“name” : “John”, “age” : 36} - ___________
x = {“apple”, “banana”, “cherry”} - ______________
x = frozenset({“apple”, “banana”, “cherry”})
- __________

A

Datatype:
list
tuple
dict
set
frozenset

21
Q

There are three numeric types in Python:

int
float
complex

A

x = 1 # int
y = 2.8 # float
z = 1j # complex

print(type(z))
<class ‘complex’>

22
Q

convert from float to int:

y = int(2.8)

z = complex(1)

A

2
(1+0j)

23
Q

import _____

print(random._____(1, 10))

A

random
randrange

8

24
Q

The len() function returns the length of a string:

A

a = “Hello, World!”
print(len(a))
13

25
Q

You can return a range of characters by using the ____ syntax.

A

slice
b = “Hello, World!”
print(b[2:5])

—>llo

26
Q

a = “Hello, World!”
print(a.upper()) - ______
print(a.lower()) - ______
print(a.strip()) - ______

A

Uppercase
lowercase
removes any whitespace from the beginning or the end

27
Q

a = “Hello, World!”
print(a.replace(“H”, “J”))

A

Jello, World!

28
Q

To insert characters that are illegal in a string, use an ______

A

escape character (")

txt = “We are the so-called "Vikings" from the north.”
print(txt)

29
Q

' Single Quote - _____

\ Backslash - ____

\n New Line

A

txt = ‘It's alright.’
It’s alright.

This will insert one \ (backslash).

30
Q

Almost any value is evaluated to ____ if it has some sort of content.

Any string is True, except _______

Any number is True, except ____

Any list, tuple, set, and dictionary are True, except ______

A

True
empty strings.
0
empty ones

31
Q

There are not many values that evaluate to ______, except empty values, such as (), [], {}, “”, the number ______, and the value None. And of course the value False evaluates to False.

A

False
0