w3 python Flashcards

1
Q

py

What is a correct syntax to output “Hello World” in Python?

A

print(“Hello World”)

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

py

How do you insert COMMENTS in Python code?

A

#

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

py

Which one is NOT a legal variable name?

A

my-var

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

py

How do you create a variable with the numeric value 5?

A

x = int(5)
or
x = 5

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

py

What is the correct file extension for Python files?

A

.py

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

py

How do you create a variable with the floating number 2.8?

A

x = float(2.8)
or
x = 2.8

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

py

What is the correct syntax to output the type of a variable or object in Python?

A

print(type(x))

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

py

What is the correct way to create a function in Python?

A

def myFunction():

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

py

In Python, ‘Hello’, is the same as “Hello”

A

True

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

py

What is a correct syntax to return the first character in a string?

A

x = “Hello”[0]

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

py

Which method can be used to remove any whitespace from both the beginning and the end of a string?

A

strip()

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

py

Which method can be used to return a string in upper case letters?

A

upper()

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

py

Which method can be used to replace parts of a string?

A

replace()

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

py

Which operator is used to multiply numbers?

A

*

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

py

Which operator can be used to compare two values?

A

==

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

py

Which set of characters are used to define a LIST?

A

[“apple”, “banana”, “cherry”]

LISTs use brackets.

17
Q

py

Which of these collections defines a TUPLE?

A

(“apple”, “banana”, “cherry”)

TUPLEs use parentheses

18
Q

py

Which of these collections defines a SET?

A

{“apple”, “banana”, “cherry”}

SETs use curly braces

19
Q

py

Which of these collections defines a DICTIONARY?

A

{“name”: “apple”, “color”: “green”}

DICTIONARIES have the first term colon construction.

20
Q

py

Which collection is ordered, changeable, and allows duplicate members?

A

LIST

21
Q

py

Which collection does not allow duplicate members?

A

SET

22
Q

py

How do you start writing an if statement in Python?

A

if x > y:

23
Q

py

How do you start writing a while loop in Python?

A

while x > y:

24
Q

py

How do you start writing a for loop in Python?

A

for x in y:

25
Q

py

Which statement is used to stop a loop?

A

break

26
Q

py

Dictionary

A

Used to store key:value pairs

Dictionaries are ordered, changeable, and do not allow duplicates.

this_dict = { "brand": "Ford", "model": "Mustang", "year": 1964 }

27
Q

py

thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 }

x = thisdict["model"]

What is X?

A

x pulls “model” from thisdict. Which is Mustang.

28
Q

py

how do you enter the python command line interpreter?

A

by typing “python” into the command line.

29
Q

py

how do you exit the python command line interpreter?

A

by typing “exit()”.

30
Q

py

how do you check your version of python on windows?

A

type “python –version” into cmd.

31
Q

py

how do you check the python version on Mac and Linux?

A

by typing “python –version” into terminal

32
Q

py

how do you run a python program from the CLI?

A

Navigate to the folder where the file is saved and type “python filename.py”

33
Q

py

What is the output:

import sys

print(sys.version)

A

the python version