Python Programming Flashcards

1
Q

What is a string in Python?

A

A sequence of characters surrounded by quotation marks.

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

Which of the following is an integer?
“123”
123
12.3
‘123’

A

123

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

How do you print the phrase “Hello, World!” in Python?

A

print(“Hello, World!”)

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

Which symbol is used for multiplication in Python?

A

*

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

What will print(“Fish”, 4) output?

A

Fish 4

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

What does the \n character do in a print statement?

A

It creates a new line.

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

What is the correct way to assign a string to a variable named ‘animal’ and print it in Python?

A

animal = “Cat”; print(animal)

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

How do you concatenate a variable a with a string “ is great” in a print statement?

A

print(a + “ is great”)

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

Which of the following correctly reads input from the user and stores it in a variable named user_age as an integer?

A

user_age = int(input(“Enter your age:”))

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

What will len(“Python”) return?

A

6

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

How do you start a comment in Python?

A

Comment

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

Which operator checks if two values are equal?

A

==

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

What is the result of 10 != 10?

A

False

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

What does the following code snippet do? if x > 10: print(“Big”) else: print(“Small”)

A

Prints “Big” if x is greater than 10, otherwise prints “Small”.

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

What will print(“Hello”[1]) output?

A

e

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

Which of the following is used to create a new list in Python?
{}
[]
()
||

A

[]

17
Q

What does the append() method do in Python?

A

Adds an element to the end of a list.

18
Q

How do you print the number of items in a list numbers?

A

print(len(numbers))

19
Q

What does the input() function return?

A

A string

20
Q

How do you remove an element from a list in Python?

A

list.pop()

21
Q

Which function converts a string into an integer?

A

int()

22
Q

What will print(2 > 3) output?

A

False

23
Q

How do you check if two variables a and b contain the same value?

A

if a == b:

24
Q

What is the result of adding two lists in Python: [1, 2] + [3, 4]?

A

[1, 2, 3, 4]

25
Q

What does the input() function do?

A

Reads a line of text from the user input.

26
Q

For Python lists, what does the index number indicate?

A

The position of an element in the list, starting at 0.

27
Q
A