Podcast
Questions and Answers
What is the output of print(2 ** 3)
?
What is the output of print(2 ** 3)
?
- 8 (correct)
- 6
- 2
- 3
How do you reverse a list in Python?
How do you reverse a list in Python?
- `list.reverse()` (correct)
- `reversed(list)`
- `list[::-1]` (correct)
- `list.sort()`
How can you check if a number is even in Python?
How can you check if a number is even in Python?
- By using the expression `number % 2 == 0` (correct)
- By using the function `is_even(number)`
- By using the expression `number / 2 == 1`
- By checking if `number` is less than 0
What is the difference between list.append() and list.extend()?
What is the difference between list.append() and list.extend()?
How do you remove duplicates from a list in Python?
How do you remove duplicates from a list in Python?
How can you convert a string to lowercase in Python?
How can you convert a string to lowercase in Python?
How do you check if a string contains only digits?
How do you check if a string contains only digits?
What is the output of print('Python'[1:4])
?
What is the output of print('Python'[1:4])
?
How can you create a dictionary with keys from a list and all values set to zero?
How can you create a dictionary with keys from a list and all values set to zero?
How do you find the length of a list in Python?
How do you find the length of a list in Python?
Flashcards are hidden until you start studying
Study Notes
Python Basics
print(2 ** 3)
outputs8
, as it uses the exponentiation operator (**).list.reverse()
orlist[::-1]
are methods to reverse a list in Python.
Number and String Operations
- To check if a number is even, use
number % 2 == 0
. string.lower()
converts a string to lowercase.- Use
string.isdigit()
to check if a string contains only digits.
Working with Lists
list.append(value)
adds a single value to the end of a list, whilelist.extend(iterable)
adds elements from an iterable.- To remove duplicates from a list, convert it to a set using
set(list)
and back to a list. print('Python'[1:4])
outputs'yth'
, as it slices the string from index 1 to 3.
Dictionaries and Lists
- Create a dictionary with keys from a list and values set to zero using
{key: 0 for key in keys_list}
. - Use
len(list)
to find the length of a list in Python.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.