Numbers, Strings & f-strings — Concept Check
Questions on Numbers, Strings & f-strings. Python ints have unlimited precision, floats are IEEE-754 doubles, and strings are immutable sequences with a rich method set — formatted beautifully with f-strings.
Questions in this quiz
8 questions on Numbers, Strings & f-strings — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In Python, what will be the result of the expression `7 // -2`?
- A4
- B-3
- C-4
- D3
2.You need to concatenate a list of words into a single string efficiently in Python. Which method should you use?
- AUse the 'join()' method
- BUse list comprehension
- CUse f-strings in a loop
- DUse the '+' operator in a loop
3.A Python program prints `0.1 + 0.2 == 0.3` as `False`. What is the reason?
- AFloats have precision issues
- BPython has a bug in float arithmetic
- CPython treats 0.1 and 0.2 as integers
- DThe expression is evaluated as a string
4.What will be the output of the following Python code: `print(f'{1234567:,}')`?
- A1,234,567
- B1234567
- C1234,567
- D1.234.567
5.You want to format a float `score = 93.4567` to two decimal places in a string. Which f-string syntax is correct?
- Af'{score:2.d}'
- Bf'{score:%2f}'
- Cf'{score:.2f}'
- Df'{score:2f}'
6.Why should you avoid comparing floats with `==` in Python?
- AFloats are stored as strings
- BFloats are mutable and change value
- CFloats are always integers in disguise
- DFloats can have precision errors
7.A developer uses `7 / 2` in a Python program ported from Java. What type will the result be?
- Aint
- Blong
- Cdouble
- Dfloat
8.How does Python handle integers that exceed typical storage limits?
- ARaises an OverflowError
- BConverts them to floats
- CTruncates the number
- DUses arbitrary precision