Skip to content
క
kagitha
/
quiz
/
python-loops
Subscribe
Index
⌘K
JAVA NOTEBOOK · QUIZ 26 · BEGINNER
Python loops and conditions
QUESTION 01 / 04
Which numbers does for i in range(1, 5): produce?
A
1, 2, 3, 4, 5
B
1, 2, 3, 4
C
0, 1, 2, 3, 4
D
2, 3, 4, 5
SCORE SO FAR · 0 / 0
Share this quiz ↗
Which numbers does for i in range(1, 5): produce?
— 1, 2, 3, 4. range stops before the stop value, like i < 5 in a Java loop. So range(1, 5) gives 1, 2, 3 and 4.
You need each chunk and its position in a list. What is the Pythonic loop?
— for i, chunk in enumerate(chunks):. enumerate gives you index and item pairs, unpacked into two names. range(len(...)) works but reads like Java written in Python.
How do you write Java's else if in Python?
— elif. Python uses the single keyword elif, followed by a condition and a colon.
What is Python's version of label = long ? "long" : "short"?
— label = "long" if long else "short". Python's conditional expression reads like a sentence: value, if condition, else fallback.
kagitha
Close
✕
Search everything — articles, videos, chapters, agents, books
01
AI
02
Java
03
System Design
04
Series
05
Manga
06
The Lab
07
Videos
08
Quizzes
09
Books
10
Resume