-
-
Notifications
You must be signed in to change notification settings - Fork 359
/
python-quiz.ts
1697 lines (1694 loc) · 72 KB
/
python-quiz.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const pythonQuiz = [
{
Question:
"In Python, what is the output of the following code: print(list(range(3, 6)))?",
Answer: "[3, 4, 5]",
Distractor1: "[3, 4, 5, 6]",
Distractor2: "[3, 6]",
Distractor3: "[3, 3, 3, 3, 3, 3]",
Explanation:
"The list(range(3, 6)) function returns a list of numbers from 3, increments by 1 (by default), and stops at 5 (excluding 6).",
Link: "https://www.freecodecamp.org/news/python-range-function-explained-with-code-examples/"
},
{
Question:
"In Python, which method is used to trim trailing whitespace from a string?",
Answer: "strip()",
Distractor1: "trim()",
Distractor2: "remove()",
Distractor3: "removesapce()",
Explanation:
"Python has three built-in methods for trimming leading and trailing whitespace and characters from strings: strip(), lstrip(), rstrip()",
Link: "https://www.freecodecamp.org/news/python-strip-how-to-trim-a-string-or-line/"
},
{
Question: "In Python, which method is used to write text to a file?",
Answer: "write()",
Distractor1: "read()",
Distractor2: "appending()",
Distractor3: "writing()",
Explanation:
"In Python the write() method is used to write text to a file.",
Link: "https://www.freecodecamp.org/news/python-create-file-how-to-append-and-write-to-a-text-file/"
},
{
Question:
"In Python, which of the following is the correct syntax for a key-value pair in a dictionary?",
Answer: "key1: value1",
Distractor1: "5j",
Distractor2: "'key'",
Distractor3: "'count'",
Explanation:
"A Python dictionary is a sequence of key-value pairs separated by commas. Here is the correct syntax: key1: value1.",
Link: "https://www.freecodecamp.org/news/python-dictionary-methods-dictionaries-in-python/"
},
{
Question:
"In Python, what is the output for this code: print(len('Hello world!'))?",
Answer: "12",
Distractor1: "11",
Distractor2: "10",
Distractor3: "13",
Explanation:
"The len function returns all characters within a string. Every single character(and space) in Hello world! would result in a length of 12.",
Link: "https://www.freecodecamp.org/news/print-statement-in-python-how-to-print-with-example-syntax-command/"
},
{
Question: "In Python, what are anonymous functions called?",
Answer: "Lambda function",
Distractor1: "Type function",
Distractor2: "beta functions",
Distractor3: "Sorted Function",
Explanation:
"Lambda functions are anonymous functions that can contain only one expression.",
Link: "https://www.freecodecamp.org/news/lambda-function-in-python-example-syntax/"
},
{
Question:
"In Python, which operator is used to perform Bitwise XOR operations?",
Answer: "^",
Distractor1: "~",
Distractor2: "|",
Distractor3: "&",
Explanation:
"The ^ operator is used in Python to perform Bitwise NOT operations.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, if organization='freeCodeCamp', then what is the result here: print(type(organization))?",
Answer: "<class 'str'>",
Distractor1: "<class 'char'>",
Distractor2: "<class 'var'>",
Distractor3: "error",
Explanation:
"Python's type() method returns the class type for the object.",
Link: "https://www.freecodecamp.org/news/python-print-type-of-variable-how-to-get-var-type/"
},
{
Question:
"In Python, if we have list=['rahul', 'monica', 'george', 'ross', 'george', 'ross'], then what is the result here: print(len(set(list))-len(list))?",
Answer: "-2",
Distractor1: "2",
Distractor2: "0",
Distractor3: "6",
Explanation:
"Lists can have duplicate items while Sets only contain unique items.",
Link: "https://www.freecodecamp.org/news/python-set-operations-explained-with-examples/"
},
{
Question:
"In Python, if we have word ='free' and phrase='code camp', then what is the result here: print(word + phrase)?",
Answer: "free code camp",
Distractor1: "free camp code",
Distractor2: "free + code camp",
Distractor3: "code camp free",
Explanation: "To concatenate two strings, you can use the + operator.",
Link: "https://www.freecodecamp.org/news/python-concatenate-strings-how-to-combine-and-append-strings-in-python/"
},
{
Question:
"In Python, which operator is used to perform Bitwise NOT operations?",
Answer: "~",
Distractor1: "++",
Distractor2: "!",
Distractor3: "--",
Explanation:
"The ~ operator is used in Python to perform Bitwise NOT operations.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, which operator is used to perform Bitwise OR operations?",
Answer: "|",
Distractor1: ">>>",
Distractor2: "<<<",
Distractor3: "x",
Explanation:
"The | operator is used in Python to perform Bitwise OR operations.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, which operator is used to perform Bitwise AND operations?",
Answer: "&",
Distractor1: "{{",
Distractor2: "&&",
Distractor3: "<",
Explanation:
"The & operator is used in Python to perform Bitwise AND operations.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, which method is used to count the set bits in an integer?",
Answer: "int.bit_count()",
Distractor1: "float.bit_count()",
Distractor2: "double.bit_count()",
Distractor3: "int.count()",
Explanation: "int.bit_count() is used to count set bits in an integer",
Link: "https://docs.python.org/3/library/stdtypes.html?highlight=tim%20sort#int.bit_count"
},
{
Question: "In Python, which module supports regular expressions?",
Answer: "re",
Distractor1: "regex",
Distractor2: "pyregex",
Distractor3: "pythonre",
Explanation: "The Python re module provides regular expression support.",
Link: "https://docs.python.org/3/library/re.html"
},
{
Question: "In Python, what keyword is used to raise exceptions?",
Answer: "raise",
Distractor1: "try",
Distractor2: "goto",
Distractor3: "except",
Explanation: "The raise keyword is used in Python to throw exceptions.",
Link: "https://www.freecodecamp.org/news/exception-handling-python/"
},
{
Question:
"In Python, which one is the correct way to get the last item for the following list: numbers = [1, 2, 3, 4, 5]?",
Answer: "All of the above",
Distractor1: "numbers[-1]",
Distractor2: "numbers[len(numbers)-1]",
Distractor3: "numbers.pop()",
Explanation:
"If you use negative indexing or the pop() method it will return the last item in the numbers list.",
Link: "https://www.freecodecamp.org/news/python-get-last-element-in-list-how-to-select-the-last-item/"
},
{
Question: "In Python, which of the following is not a complex number?",
Answer: "2 + 3l",
Distractor1: "2 + 3j",
Distractor2: "complex(2, 3)",
Distractor3: "2 + 3J",
Explanation:
"In Python, the letter 'l' (or L) stands for long and 2 + 3l would not result in a complex number.",
Link: "https://forum.freecodecamp.org/t/an-introduction-to-python-complex-numbers-explained-with-examples/19218"
},
{
Question:
"In Python, which of the following list methods directly modifies the original list?",
Answer: "sort()",
Distractor1: "sorted()",
Distractor2: "reversed()",
Distractor3: "None of the above",
Explanation:
"sort() and reverse() directly modify the original list, while sorted() and reversed() return a copy of the original list.",
Link: "https://www.freecodecamp.org/news/python-sort-how-to-sort-a-list-in-python/"
},
{
Question:
"In Python, which of the following options will reverse this string: sentence='freeCodeCamp rules'?",
Answer: "sentence[::-1]",
Distractor1: "reversed(sentence)",
Distractor2: "sentence.reverse()",
Distractor3: "sentence.sort(reverse=True)",
Explanation: "In Python, [::-1] will return a reversed copy of the string.",
Link: "https://www.freecodecamp.org/news/python-reverse-string-string-reversal-in-python-explained-with-code-examples/"
},
{
Question:
"In Python, which module provides a framework for writing line-oriented command interpreters?",
Answer: "cmd",
Distractor1: "sys",
Distractor2: "os",
Distractor3: "io",
Explanation:
"The cmd module makes it easier to use a series of commands within command-line interfaces (CLI)",
Link: "https://docs.python.org/3/library/cmd.html"
},
{
Question:
"In Python, which module provides a way of using operating system dependent functionality?",
Answer: "os",
Distractor1: "sys",
Distractor2: "builtins",
Distractor3: "io",
Explanation:
"The Python os module is a set of functions used within the operating system. Some of these functions include fetching directory contents or creating new directories.",
Link: "https://docs.python.org/3/library/os.html"
},
{
Question:
"In Python, which module is used to capture command-line arguments given at a file's runtime ?",
Answer: "sys",
Distractor1: "os",
Distractor2: "collections",
Distractor3: "itertools",
Explanation: "We can use sys.argv to get a list of command line arguments.",
Link: "https://docs.python.org/3/library/sys.html#sys.argv"
},
{
Question: "What will be the output of following code 2//4?",
Answer: "0",
Distractor1: "0.5",
Distractor2: "0",
Distractor3: "2",
Explanation:
"The division of operands where the result is the quotient in which the digits after the decimal point are removed",
Link: "https://www.freecodecamp.org/news/what-does-double-slash-mean-in-python/"
},
{
Question:
"In Python 3, which function is used to accept input from the user?",
Answer: "input()",
Distractor1: "inputing()",
Distractor2: "raw_input()",
Distractor3: "string()",
Explanation: "To take input from the user we use the input() function",
Link: "https://forum.freecodecamp.org/t/a-guide-to-the-python-input-function/19192"
},
{
Question: "In Python, what does a class's __init__() method do?",
Answer:
"It is a method that acts as a constructor and is called automatically whenever a new object is created from a class. It sets the initial state of a new object.",
Distractor1:
"It initializes any imports you may have included at the top of your file.",
Distractor2: "It is included to preserve backwards compatibility issues.",
Distractor3:
"It is a method that acts as a destructor and is called automatically whenever an object is destroyed.",
Explanation:
" __init__() is a special method that is called whenever a new object is instantiated from a class. It is used to initialize the attributes of the class.",
Link: "https://www.freecodecamp.org/news/object-oriented-programming-in-python/"
},
{
Question:
"In Python, which of the following is NOT a parameter of the sorted() method?",
Answer: "iloc",
Distractor1: "key",
Distractor2: "iterable",
Distractor3: "reverse",
Explanation:
"The sorted() method can accept up to 3 parameters which are iterable, key and reverse",
Link: "https://www.freecodecamp.org/news/sort-dictionary-by-value-in-python/"
},
{
Question:
"In Python, which of the following is not an attribute of the datetime.now() function?",
Answer: "week",
Distractor1: "month",
Distractor2: "day",
Distractor3: "year",
Explanation:
"The attributes of the datetime.now() function are year, month, day, hour, minute, second and microsecond",
Link: "https://www.freecodecamp.org/news/python-datetime-now-how-to-get-todays-date-and-time/"
},
{
Question:
"What is the output of the following Python code: print((10, 20, 30, 40, 50, 60, 70, 80)[2:5])?",
Answer: "(30, 40, 50)",
Distractor1: "(10, 30 ,40, 50)",
Distractor2: "(30, 40, 50)",
Distractor3: "(10, 20, 30)",
Explanation:
"To get a sub tuple out of the Tuple, we need to specify the range of indexes. We need to specify where to start and where to end the range.",
Link: "https://forum.freecodecamp.org/t/the-ultimate-guide-to-python-tuples-python-data-structure-tutorial-with-code-examples/19165"
},
{
Question:
"What is the output of the following Tuple Operation in Python: print((100,) * 2)?",
Answer: "(100,100)",
Distractor1: "(200)",
Distractor2: "(100)",
Distractor3: "(100,100)",
Explanation:
"We can use * operator to repeat the tuple values n number of times.",
Link: "https://forum.freecodecamp.org/t/the-ultimate-guide-to-python-tuples-python-data-structure-tutorial-with-code-examples/19165"
},
{
Question: "In Python, which of the following outputs 'camp'?",
Answer: "print('freecodecamp'[-4:])",
Distractor1: "print('freecodecamp'[8::-1])",
Distractor2: "print('freecodecamp'[8:11])",
Distractor3: "print('freecodecamp'[-4:10])",
Explanation:
"Here we use the negative index to start slicing at the 4th index from the end of the string.",
Link: "https://www.freecodecamp.org/news/python-substring-how-to-slice-a-string/#how-to-get-the-last-n-characters-of-a-string-in-python"
},
{
Question:
"In Python, which Type casting method lets users convert a specific data type into a required data type?",
Answer: "Explicit Type Conversion",
Distractor1: "Implicit Type Conversion",
Distractor2: "Default Type Conversion",
Distractor3: "Widening Type Conversion",
Explanation:
"In Explicit Type Conversion, users convert the data type of an object to the required data type.",
Link: "https://www.freecodecamp.org/news/learn-typecasting-in-python-in-five-minutes-90d42c439743/#explicit-type-conversion"
},
{
Question: "In Python, which one of these is not a Dunder method?",
Answer: "__func",
Distractor1: "__init__",
Distractor2: "__add__",
Distractor3: "__len__ ",
Explanation:
"Dunder methods are names that are preceded and succeeded by double underscores, hence __func method is not a Dunder method.",
Link: "https://docs.python.org/3/reference/lexical_analysis.html?highlight=dunder#reserved-classes-of-identifiers"
},
{
Question: "In Python, what are the outputs for type(1) and type((1,))?",
Answer: "<class 'int'> <class 'tuple'>",
Distractor1: "<class 'str'> <class 'int'>",
Distractor2: "<class 'dict'> <class 'list'>",
Distractor3: "<class 'int'> <class 'int'> ",
Explanation:
"type(1) will return <class 'int'> and type((1,)) will return <class 'tuple'>",
Link: "https://www.freecodecamp.org/news/python-tuple-vs-list-what-is-the-difference/"
},
{
Question:
"In Python, which method can be used to replace parts of a string?",
Answer: "replace()",
Distractor1: "switch()",
Distractor2: "repl()",
Distractor3: "find()",
Explanation:
"If you need to search through a string for a pattern, and replace it with another pattern, you can use the replace() method.",
Link: "https://www.freecodecamp.org/news/python-string-methods-tutorial-how-to-use-find-and-replace-on-python-strings/"
},
{
Question: "In Python, what is the correct way to create a function?",
Answer: "def function_name(parameters):",
Distractor1: "function function_name(parameter):",
Distractor2: "definition function_name {[parameters]}:",
Distractor3: "create function_name(parameters):",
Explanation:
"The following snippet shows the general syntax to define a function in Python: def function_name(parameters):",
Link: "https://www.freecodecamp.org/news/functions-in-python-a-beginners-guide/"
},
{
Question: "In Python, what is a correct syntax to output 'Hello World'?",
Answer: "print('Hello World')",
Distractor1: "echo('Hello World')",
Distractor2: "p('Hello World')",
Distractor3: "printf('Hello World')",
Explanation: "To print anything in Python, you use the print() function.",
Link: "https://www.freecodecamp.org/news/python-print-variable-how-to-print-a-string-and-variable/"
},
{
Question: "In Python, how can you create an empty dictionary?",
Answer: "{}",
Distractor1: "[]",
Distractor2: "()",
Distractor3: "list()",
Explanation: "You can create an empty dictionary with {} in Python.",
Link: "https://www.freecodecamp.org/news/python-dictionaries-detailed-visual-introduction/"
},
{
Question: "In Python, how can you create an empty set?",
Answer: "set()",
Distractor1: "{}",
Distractor2: "dict()",
Distractor3: "()",
Explanation:
"You must call the set() function to create an empty set in Python.",
Link: "https://www.freecodecamp.org/news/python-sets-detailed-visual-introduction/"
},
{
Question:
"In Python, the value of empty sequences, collections, and the number 0 are all ...",
Answer: "Falsy",
Distractor1: "Truthy",
Distractor2: "FALSENESS",
Distractor3: "TRUENESS",
Explanation:
"Empty sequences, collections, and the number 0 are falsy values in Python.",
Link: "https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/"
},
{
Question:
"In Python, what operator can you use to check if a value is in a sequence?",
Answer: "in",
Distractor1: "member",
Distractor2: "inside",
Distractor3: "partof",
Explanation:
"The in operator is a membership operator in Python. It can be used to check if a value is in a sequence or not because it returns True if the value is in the list and False if it is not in the list. ",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, a value that evaluates to True in a boolean context is known as...",
Answer: "Truthy",
Distractor1: "TRUENESS",
Distractor2: "Falsy",
Distractor3: "Truthful",
Explanation:
"A value that evaluates to True in a boolean context is known as a truthy value.",
Link: "https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/"
},
{
Question:
"In Python, what logical operator returns True if both operands are True?",
Answer: "and",
Distractor1: "or",
Distractor2: "not",
Distractor3: "list",
Explanation:
"The and operator returns True if both operands are True and False otherwise.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question: "In Python, what is the “greater than” operator?",
Answer: ">",
Distractor1: ">=",
Distractor2: "<",
Distractor3: "<=",
Explanation:
"The “greater than” operator is > in Python. It returns True if the value on the left is greater than the value on the right. We can also use it to compare strings in alphabetical order.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question:
"The canonical implementation of the Python programming language, as distributed on python.org is known as...",
Answer: "CPython",
Distractor1: "PPython",
Distractor2: "QPython",
Distractor3: "MPython",
Explanation:
"CPython is the canonical implementation of the Python programming language, as distributed on python.org. Canonical is a software company",
Link: "https://docs.python.org/3/glossary.html"
},
{
Question: "When did Python first appear?",
Answer: "1991",
Distractor1: "2001",
Distractor2: "2011",
Distractor3: "2021",
Explanation: "Python first appeared in 1991.",
Link: "https://en.wikipedia.org/wiki/Python_(programming_language)"
},
{
Question: "In Python, what is the addition assignment operator?",
Answer: " +=",
Distractor1: " =+",
Distractor2: " +",
Distractor3: "==",
Explanation:
"The += operator lets you add a value (right operand) to the current value of a variable and store the result of the calculation in the same variable (left operand). This is shorter than using + and then = separately.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question: "In Python, what is the meaning of PEP?",
Answer: "Python Enhancement Proposal",
Distractor1: "Python Experimentation Platform",
Distractor2: "Python Excellent Performance",
Distractor3: "Python Environmental Protection",
Explanation:
"In the context of Python, PEP means Python Enhancement Proposal. A PEP is a design document that provides information to the Python community, or describes a new feature for Python or its processes or environment.",
Link: "https://www.python.org/dev/peps/pep-0001/#what-is-a-pep"
},
{
Question: "In Python, what is the correct way to write Boolean values?",
Answer: "True/False",
Distractor1: "true/false",
Distractor2: "TRUE/FALSE",
Distractor3: "tRuE/FaLsE",
Explanation:
"In Python, we have to write Boolean values like this: True and False. If we don't write them like this, they will not be recognized as keywords in the program. ",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/"
},
{
Question: "In Python, what is the result of this code: “Hi” * 2?",
Answer: "HiHi",
Distractor1: "“Hihi”",
Distractor2: "“HiHiHiHi”",
Distractor3: "A SyntaxError",
Explanation:
"The * operator in Python can be used to repeat a string a given number of times. In this case, the string “Hi” is repeated two times. ",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question:
"In Python, what is the name of a value associated with an object that can be referenced by its name using dot notation?",
Answer: "Attribute",
Distractor1: "Property",
Distractor2: "Characteristic",
Distractor3: "Method",
Explanation:
"An attribute is a value associated with an object that can be referenced by its name using dot notation.",
Link: "https://docs.python.org/3/glossary.html"
},
{
Question: "In Python, what is the “less than or equal to” operator?",
Answer: "<=",
Distractor1: "<",
Distractor2: ">",
Distractor3: ">=",
Explanation:
"The “less than or equal to” operator is <= in Python. It returns True if the value on the left is less than or equal to the value on the right. We can also use it to compare strings in alphabetical order.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question:
"In Python, what built-in function returns the largest item in an iterable or the largest of two or more arguments?",
Answer: "max()",
Distractor1: "min()",
Distractor2: "maximum()",
Distractor3: "largest()",
Explanation:
"The max() function returns the largest item in an iterable or the largest of two or more arguments.",
Link: "https://www.freecodecamp.org/news/python-function-guide-with-examples/"
},
{
Question: "In Python, which of these is not a keyword?",
Answer: "forward",
Distractor1: "if",
Distractor2: "return",
Distractor3: "for",
Explanation:
"The words if, return, and for, are Python keywords but forward is not a Python keyword. Python keywords are reserved words, so they cannot be used as variable names, function names, or any other identifiers in a Python program. ",
Link: "https://forum.freecodecamp.org/t/python-keywords-a-guide-with-examples/19188"
},
{
Question:
"In Python, what built-in data structure can store key-value pairs? ",
Answer: "Dictionary",
Distractor1: "List",
Distractor2: "Boolean",
Distractor3: "String",
Explanation:
"A dictionary can store key-value pairs, which are pairs of associated values. We use the key to access its corresponding value in the dictionary. ",
Link: "https://www.freecodecamp.org/news/python-dictionaries-detailed-visual-introduction/"
},
{
Question:
"In Python, what method is used to remove a key-value pair from a dictionary and return its value?",
Answer: ".pop()",
Distractor1: ".push()",
Distractor2: ".append()",
Distractor3: ".insert()",
Explanation:
"The .pop() method is used to remove a key-value pair from the dictionary and return the value.",
Link: "https://www.freecodecamp.org/news/python-dictionaries-detailed-visual-introduction/"
},
{
Question: "In Python, what is the floor division operator?",
Answer: "//",
Distractor1: "/",
Distractor2: "*",
Distractor3: "**",
Explanation:
"The floor division operator in Python is //. This operator performs a mathematical division that rounds down to the nearest integer.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, what value does a function return by default if it doesn't have a return statement?",
Answer: "None",
Distractor1: "0",
Distractor2: "An empty string",
Distractor3: "An empty list",
Explanation:
"Python functions return the special value of None if they do not have an explicit return statement.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-functions-in-python"
},
{
Question: "In Python, what keyword is used to define a class?",
Answer: "class",
Distractor1: "def",
Distractor2: "blueprint",
Distractor3: "create",
Explanation: "The class keyword is used in Python to define a class.",
Link: "https://www.freecodecamp.org/news/learn-object-oriented-programming-with-python/"
},
{
Question:
"In Python, what built-in function returns the smallest item in an iterable or the smallest of two or more arguments?",
Answer: "min()",
Distractor1: "max()",
Distractor2: "minimum()",
Distractor3: "smallest)",
Explanation:
"The min() function returns the smallest item in an iterable or the smallest of two or more arguments.",
Link: "https://www.freecodecamp.org/news/python-function-guide-with-examples/"
},
{
Question:
"In Python, what is the name of the exception raised when a name that you are referencing in the code doesn't exist?",
Answer: "NameError",
Distractor1: "KeyError",
Distractor2: "IndexError",
Distractor3: "TypeError",
Explanation:
"A NameError is raised in Python when a name that you are referencing in the code doesn't exist.",
Link: "https://www.freecodecamp.org/news/exception-handling-python/"
},
{
Question:
"In Python, which one of these operators is used to raise a number to the power of an exponent? ",
Answer: "**",
Distractor1: "*",
Distractor2: "^",
Distractor3: "!",
Explanation:
"The power operator is ** in Python. We use it to raise the number on the left to the power of the exponent on the right. For example, 5 ** 3 means 5 raised to the power 3. The result would be 125.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question:
"In Python, what built-in function returns a number rounded to a given number of digits of precision after the decimal point?",
Answer: "round()",
Distractor1: "rounding()",
Distractor2: "approximate()",
Distractor3: "decimal()",
Explanation:
"The round() function returns a number rounded to a given number of digits of precision after the decimal point.",
Link: "https://docs.python.org/3/library/functions.html#round"
},
{
Question:
"In Python, non-empty sequences, non-empty collections, and numerical values different from 0 are...",
Answer: "Truthy",
Distractor1: "Falsy",
Distractor2: "TRUENESS",
Distractor3: "FALSENESS",
Explanation:
"Non-empty sequences, collections, and numerical values different from 0 are truthy values.",
Link: "https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/"
},
{
Question: "In Python, how can you create an empty list?",
Answer: "[]",
Distractor1: "dict()",
Distractor2: "??",
Distractor3: "(())",
Explanation:
"You can create an empty list with [] or with list() in Python.",
Link: "https://www.freecodecamp.org/news/python-empty-list-tutorial-how-to-create-an-empty-list-in-python/"
},
{
Question:
"In Python, what is the name of the exception raised when an operation or function is applied to an object of an inappropriate type? ",
Answer: "TypeError",
Distractor1: "NameError",
Distractor2: "KeyError",
Distractor3: "IndexError",
Explanation:
"A TypeError is raised in Python when an operation or function is applied to an object of an inappropriate type. ",
Link: "https://www.freecodecamp.org/news/exception-handling-python/"
},
{
Question:
"In Python, what function returns True if any element of the iterable evaluates to True?",
Answer: "any()",
Distractor1: "all()",
Distractor2: "none()",
Distractor3: "one()",
Explanation:
"The any() function returns True if any element of the iterable passed as an argument evaluates to True. Else, it returns False.",
Link: "https://www.freecodecamp.org/news/python-any-and-all-functions-explained-with-examples/"
},
{
Question: "In Python, how can you write a “Hello, World” program?",
Answer: "print(“Hello, World!”)",
Distractor1: "console.log(“Hello, World!”)",
Distractor2: "show(“Hello, World!”)",
Distractor3: "console(“Hello, World!”)",
Explanation:
"In Python, we use the built-in print() function to print a value to the console. We pass the value as an argument within parentheses. ",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-hello-world-program-in-python"
},
{
Question: "In Python, how do you define a variable?",
Answer: "<variable_name> = <value>",
Distractor1: "<value> = <variable_name>",
Distractor2: "<value> <= <variable_name>",
Distractor3: "<variable_name> <= <value>",
Explanation:
"In Python, we define a variable with <variable_name> = <value>.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/"
},
{
Question:
"In Python, string literals prefixed with 'f' or 'F' are commonly called...",
Answer: "f-strings",
Distractor1: "strings-f",
Distractor2: "p-string",
Distractor3: "x-string",
Explanation:
"f-strings are string literals prefixed with 'f' and 'F' in Python.",
Link: "https://www.freecodecamp.org/news/python-f-strings-tutorial-how-to-use-f-strings-for-string-formatting/"
},
{
Question: "In Python, what is the modulo operator?",
Answer: "%",
Distractor1: "//",
Distractor2: "/",
Distractor3: "^",
Explanation:
"The modulo operator in Python is %. It returns the remainder of dividing the left hand operand by right hand operand.",
Link: "https://www.freecodecamp.org/news/the-python-modulo-operator-what-does-the-symbol-mean-in-python-solved/"
},
{
Question:
"In Python, what function can you call to get interactive help on writing Python programs and using Python modules?",
Answer: "help()",
Distractor1: "please()",
Distractor2: "helpme()",
Distractor3: "assistance()",
Explanation:
"The help() function can be called in Python to get interactive help on writing Python programs and using Python modules.",
Link: "https://docs.python.org/3/library/functions.html#help"
},
{
Question:
"In Python, what logical operator returns True if any of the operands are True?",
Answer: "or",
Distractor1: "and",
Distractor2: "not",
Distractor3: "console",
Explanation:
"The or operator returns True if any of the operands is True. ",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, what keyword is used to return a value from a function?",
Answer: "return",
Distractor1: "pass",
Distractor2: "continue",
Distractor3: "break",
Explanation:
"The return keyword is used to return a value from a function.This terminates the execution of the function to return the value.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-functions-in-python"
},
{
Question:
"In Python, which one of these operators has the highest precedence?",
Answer: "**",
Distractor1: "/",
Distractor2: "*",
Distractor3: "and",
Explanation:
"The exponentiation operator ** has the highest precedence of these four options.",
Link: "https://docs.python.org/3/reference/expressions.html#operator-precedence"
},
{
Question: "In Python, what is the “less than” operator?",
Answer: "<",
Distractor1: ">",
Distractor2: "<=",
Distractor3: ">=",
Explanation:
"The “less than” operator is < in Python. It returns True if the value on the left is less than the value on the right. We can also use it to compare strings in alphabetical order.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question:
"In Python, what is the name of the exception raised when you try to divide by zero?",
Answer: "ZeroDivisionError",
Distractor1: "TypeError",
Distractor2: "NameError",
Distractor3: "KeyError",
Explanation:
"A ZeroDivisionError is raised in Python when you try to divide by zero.",
Link: "https://www.freecodecamp.org/news/exception-handling-python/"
},
{
Question:
"In Python, what logical operator returns True if the operand is False?",
Answer: "not",
Distractor1: "and",
Distractor2: "or",
Distractor3: "array",
Explanation:
"The not operator returns True if the operand is False and False if the operand is True.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question: "In Python, what function can you call to open a file?",
Answer: "open()",
Distractor1: "read()",
Distractor2: "extend()",
Distractor3: "print()",
Explanation: "The open() function opens a file in a Python program. ",
Link: "https://www.freecodecamp.org/news/python-write-to-file-open-read-append-and-other-file-handling-functions-explained/"
},
{
Question:
"In Python, what module provides access to the mathematical functions defined by the C standard?",
Answer: "math",
Distractor1: "functions",
Distractor2: "algebra",
Distractor3: "calculus",
Explanation:
"The math module provides access to the mathematical functions defined by the C standard in Python.",
Link: "https://docs.python.org/3/library/math.html#module-math"
},
{
Question:
"In Python, the integer used to refer to a character in a string or an element in a list or tuple is known as an...",
Answer: "index",
Distractor1: "integer",
Distractor2: "location",
Distractor3: "position",
Explanation:
"Strings, lists, tuples, and other sequences in Python have indices, which are integers used to refer to its elements. ",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-data-types-and-built-in-data-structures-in-python"
},
{
Question:
'In Python, how can you check if the key "Nora" is in the "names" dictionary?',
Answer: '"Nora" in names',
Distractor1: 'names in "Nora"',
Distractor2: '"Nora" is in names',
Distractor3: 'names is in "Nora"',
Explanation:
'To check if a key is in a dictionary, first we write the key followed by in and then the name of the dictionary. In this case, the correct option is "Nora" in names.',
Link: "https://www.freecodecamp.org/news/python-dictionaries-detailed-visual-introduction/"
},
{
Question:
"In Python, what method takes an iterable as an argument and adds the elements of that iterable to a list as individual elements?",
Answer: ".extend()",
Distractor1: ".append()",
Distractor2: ".join()",
Distractor3: ".add()",
Explanation:
"The .extend() method takes an iterable as an argument and adds the elements of that iterable to a list as individual elements.",
Link: "https://www.freecodecamp.org/news/python-list-append-vs-python-list-extend/"
},
{
Question: "In Python, are lists mutable or immutable?",
Answer: "Mutable",
Distractor1: "Immutable",
Distractor2: "Neither Mutable or Immutable",
Distractor3: "Both Mutable and Immutable",
Explanation:
"Lists are mutable built-in data structures in Python. This means that you can add new elements to a list, update the elements of a list, and remove elements from a list.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-data-types-and-built-in-data-structures-in-python"
},
{
Question:
"In Python, what function returns True if all the elements of an iterable evaluate to True?",
Answer: "all()",
Distractor1: "any()",
Distractor2: "none()",
Distractor3: "zero()",
Explanation:
"The all() function returns True if all the elements of the iterable passed as an argument evaluate to True. Else, it returns False.",
Link: "https://www.freecodecamp.org/news/python-any-and-all-functions-explained-with-examples/"
},
{
Question:
"In Python, what function can you use to transform a number represented as a string into an integer?",
Answer: "int()",
Distractor1: "float()",
Distractor2: "complex()",
Distractor3: "bin()",
Explanation:
"The int() function takes a string as an argument and returns an integer.",
Link: "https://www.freecodecamp.org/news/how-to-convert-strings-into-integers-in-python/"
},
{
Question: "In Python, what is the “greater than or equal to” operator?",
Answer: ">=",
Distractor1: ">",
Distractor2: "<",
Distractor3: "<=",
Explanation:
"The “greater than or equal to” operator is >= in Python. It returns True if the value on the left is greater than or equal to the value on the right. We can also use it to compare strings in alphabetical order.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-python-operators"
},
{
Question: "In Python, the first index of a sequence is...",
Answer: "0",
Distractor1: "1",
Distractor2: "-1",
Distractor3: "2",
Explanation: "The first index of a sequence in Python is 0.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-data-types-and-built-in-data-structures-in-python"
},
{
Question: "In Python, what keyword is used to define a function?",
Answer: "def",
Distractor1: "class",
Distractor2: "if",
Distractor3: "return",
Explanation: "The def keyword is used to define a function in Python.",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-functions-in-python"
},
{
Question: "In Python, strings are...",
Answer: "Immutable",
Distractor1: "Mutable",
Distractor2: "Maintainable",
Distractor3: "Unstoppable",
Explanation:
"Strings are immutable, so we can't update or remove their characters after they have been defined in the program. ",
Link: "https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/#-data-types-and-built-in-data-structures-in-python"
},
{
Question: "Who created the Python programming language?",
Answer: "Guido van Rossum",
Distractor1: "Ada Lovelace",
Distractor2: "Alan Turing",
Distractor3: "Tim Berners-Lee",
Explanation: "Guido van Rossum created the Python programming language.",
Link: "https://en.wikipedia.org/wiki/Python_(programming_language)"
},
{
Question:
"In Python, which of the following operators is NOT a bitwise operator?",
Answer: "%",
Distractor1: "&",
Distractor2: "|",
Distractor3: "~",
Explanation:
"% is the modulo operator in Python. The operators &, |, and ~ are bitwise operators.",
Link: "https://www.freecodecamp.org/news/basic-operators-in-python-with-examples/"
},
{
Question:
"In Python, what is the data type of the value returned by the input() function?",
Answer: "String",
Distractor1: "Integer",
Distractor2: "Boolean",
Distractor3: "List",
Explanation:
"The built-in function input() always returns a string. If you need to work with this value as a different data type, you will need to convert it.",
Link: "https://www.freecodecamp.org/news/python-function-guide-with-examples/"
},
{
Question:
"In Python, what built-in function returns a reverse iterator that allows you to iterate over the elements of an iterable in reverse order?",
Answer: "reversed()",
Distractor1: "sorted()",
Distractor2: "reversing()",
Distractor3: "backwards()",
Explanation:
"The reversed() function returns a reverse iterator that you can use to iterate over an iterable in reverse order.",
Link: "https://docs.python.org/3/library/functions.html#reversed"
},
{
Question: "In Python, the keys of a dictionary must be...",
Answer: "Immutable",
Distractor1: "Mutable",
Distractor2: "Both will work",
Distractor3: "Neither will work",
Explanation: "The keys of a Python dictionary must be immutable.",
Link: "https://www.freecodecamp.org/news/python-dictionaries-detailed-visual-introduction/"
},
{
Question:
"In Python, it is recommended to write variable names in lowercase with words separated by...",
Answer: "an underscore",