1) Which of the following statements contain valid Python string literals? Select all that are correct: a) string = 'We're #1!' b) string = Hello, world. c) string = "1234" d) string = 'Hello, world.' e) string = 1234 f) string = "We're #1!" 2) Joining two strings with the + operator is called… a) A string method b) String concatenation c) String slicing d) String indexing 3) String methods change the original string. a) True b) False 4) What’s the value of x after this code snippet executes?  x = 1234 + 5 a) '1239' b) 1239 c) 12345 d) '12345' 5) What’s the value of x after this code snippet executes? x = "1234" + 5 a) Trick question—this fails with a TypeError b) 12345 c) '12345' d) '1239' 6) What is the output of print(10 - 4 * 2) a) 2 b) 12 7) What is the output of the expression print(18 // 4) a) -4 b) 4 c) -5 d) 5 8) a = [10, 20, 30, 40, 50] Which output is different from the others? a) print(a[::]) b) print(a[0:4]) c) print(a[0:5]) d) print(a[0:len(a)]) 9) What is the output of print(2 ** 3 ** 2) Caution: the exponent operator works from right to left. a) 64 b) 512 10) What is the output of the following code print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j)) a) True True False True b) False True True True c) True True False False d) False True False True 11) Select which is true for Python tuple. Select all that are correct: a) A tuple maintains the order of items b) A tuple is unordered c) We cannot change the tuple once created d) We can change the tuple once created

Python Exercises (print,operators,list,string)

Ledertavle

Visuell stil

Alternativer

Bytt mal

Gjenopprett automatisk lagring: ?