










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A wide range of python fundamentals, including basic data types, operators, control structures, functions, and modules. It provides a comprehensive overview of the core concepts and syntax of the python programming language, making it a valuable resource for both beginners and experienced developers looking to solidify their understanding of the language. A variety of topics, from basic input/output and string manipulation to more advanced concepts like file handling, exception handling, and recursive functions. By working through the examples and answering the questions presented, readers will gain a strong foundation in python programming and be well-equipped to tackle more complex projects and challenges.
Typology: Exams
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Which of the following data types are not supported in Python? - correct answer ✔✔List, Set, Dict, Tuple Which of the following data types are not supported in Python? - correct answer ✔✔int, string What is the output of print(str) if str = 'Hello World!'? - correct answer ✔✔Hello World! What is the output of print(str[0]) if str = 'Hello World!'? - correct answer ✔✔H What is the output of print(str[2:5]) if str = 'Hello World!'? - correct answer ✔✔llo What is the output of print(str[2:]) if str = 'Hello World!'? - correct answer ✔✔llo World! What is the output of print(str * 2) if str = 'Hello World!'? - correct answer ✔✔Hello World!Hello World! What is the output of print(list) if list=[ 'abcd', 786 ,2.23]? - correct answer ✔✔['abcd', 786, 2.23] What is the output of print(list[0]) if list =['abcd',786, 2.23]? - correct answer ✔✔abcd What is the output of print(list[1:3]) if list=['abcd', 786,2.23]? - correct answer ✔✔[786, 2.23] What is the output of print(list[2:]) if list=[ 'abcd',786, 2.23]? - correct answer ✔✔[2.23] What is the output of print (tinylist *2) if tinylist = [123, 'john']? - correct answer ✔✔[123, 'john', 123, 'john']
Which of the following is correct about tuples in Python? - correct answer ✔✔you cant change them What is the output of print(myTuple) if myTuple = ('abcd',786,2.23)? - correct answer ✔✔('abcd', 786, 2.23) What is the output of print(myTuple[1:3]) if myTuple=('abcd',786,2.23)? - correct answer ✔✔(786, 2.23) What is the output of print(myTuple[0]) if myTuple = ('abcd',786,2.23)? - correct answer ✔✔abcd Which function obtains all the keys from a dictionary? - correct answer ✔✔keys() Which function obtains all the values from a dictionary? - correct answer ✔✔values() Which function converts a string to an int? - correct answer ✔✔int() Which function converts a string to a float? - correct answer ✔✔float() Which function converts a string to a tuple? - correct answer ✔✔tuple() Which function converts a string to a list? - correct answer ✔✔list() Which function converts a sequence of tuples to dictionary? - correct answer ✔✔dict() Which function converts an integer to a character? - correct answer ✔✔chr() Which function converts an integer to an unicode character? - correct answer ✔✔unichr() Which function converts a single character to its integer value? - correct answer ✔✔ord(x)
Which function checks in a string that all characters are digits? - correct answer ✔✔unicodedata.numeric(s) Which function checks in a string that all characters are in lowercase? - correct answer ✔✔islower Which function checks in a string that all characters are numeric? - correct answer ✔✔isnumeric Which function checks in a string that all characters are whitespaces? - correct answer ✔✔isspace Which function checks in a string that all characters are titlecased? - correct answer ✔✔istitle Which function checks in a string that all characters are in uppercase? - correct answer ✔✔isupper Which function merges elements in a sequence? - correct answer ✔✔joinseq Which function converts a string to all lowercase? - correct answer ✔✔string.lower() Which function removes all leading whitespace in a string? - correct answer ✔✔strip[chars] Which function returns the max character from a string? - correct answer ✔✔max(str) Which function returns the min character from a string? - correct answer ✔✔min(str) Which function replaces a substring in string with new string - correct answer ✔✔str.replace(old, new[, max]) What is the output of [1,2,3]+[4,5,6]? - correct answer ✔✔[1,2,3,4,5,6]
What is the output of ['Hi!'] * 4? - correct answer ✔✔['Hi!', 'Hi!', 'Hi!', 'Hi!'] What is the output of 3 in [1, 2, 3]? - correct answer ✔✔ 2 What is the output of L[2] if L = [1,2,3]? - correct answer ✔✔ 3 What is the output of L[-2] if L = [1,2,3]? - correct answer ✔✔ 2 What is the output of L[1:] if L = [1,2,3]? - correct answer ✔✔[2,3] What is the function that compares elements of lists? - correct answer ✔✔cmp() What is the function that returns the lowest index in list? - correct answer ✔✔min What is the function that inserts an object at given index in a list? - correct answer ✔✔ What is the function that removes last object from a list? - correct answer ✔✔remove What is the function that removes an object from a list? - correct answer ✔✔del() What is the function that reverses objects of list in place? - correct answer ✔✔reverse() What is the value of the counter after counter +=1? - correct answer ✔✔counter + 1 Why is does 74.95.1 evaluate to 7.495000000000001 instead of 7.495? - correct answer ✔✔evaluating long instead of short What does the = operator perform? - correct answer ✔✔a=b: a=(ab)
What is the result of 4 == 5 and 3 > 2 - correct answer ✔✔false What is the result of 4!=4 or 4<2? - correct answer ✔✔false What is the result of True and True and True and False - correct answer ✔✔false What is the result True or False - correct answer ✔✔ What is the result of "apple" < "Apple"? - correct answer ✔✔False What is the result of "App" < "Apple"? - correct answer ✔✔True What is the result of "1"< "5" - correct answer ✔✔True What is the result of "10"<"5" - correct answer ✔✔True What does the pass statement do? - correct answer ✔✔The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. The pass statement is a null operation; nothing happens when it executes. How does range(5) evaluate in Python? - correct answer ✔✔0,1,2,3,4, How does range(1,6) evaluate in Python? - correct answer ✔✔1,2,3,4, How does range(2,10,2) evaluate in Python? - correct answer ✔✔2,4,6,8, How does range(5, 0,-1) evaluate in Python? - correct answer ✔✔5,4,3,2, sum=0, what is the value of sum after, for i in range(1,5): sum +=i? - correct answer ✔✔
What statement breakouts by jumping to the statement that follows a loop? - correct answer ✔✔break What statement is used to jump to the top of the loop? - correct answer ✔✔continue What is a module in Python? - correct answer ✔✔A module is a file containing Python definitions and statements. What is an incorrect fact about a Python function? - correct answer ✔✔ What is not a syntax error in Python? - correct answer ✔✔error in how code is written not a logic error temps = [48.0, 30.5, 20.2, 100.0, 42.0]. What is temps[5]? - correct answer ✔✔48. inventory =["staff","hat","robe","bread"]. What is inventory.index("hat")? - correct answer ✔✔ 1 What key word is used in a for statement to print each item in a list? - correct answer ✔✔ Which is a mutable type in Python? - correct answer ✔✔list, set, dict What happens when you pass a mutable object like a list to a function? - correct answer ✔✔ list movies= [["The Holy Grail",1975],["Sting", 1973]]. What is movies[1][0]? - correct answer ✔✔sting numlist=[5, 15, 84, 3, 14,2, 8,10,14,25]. What is numlist.count(14)? - correct answer ✔✔ 2 numlist = [ 5, 15, 84,3,14, 2,8,10,14,25]. What is min(numlist)? - correct answer ✔✔ 2 What is the syntax to create a list? - correct answer ✔✔L = []
What is the keyword used in a for statement to search a string? - correct answer ✔✔ What does the % operator do in Python? - correct answer ✔✔modulus operation What does the // operator do in Python? - correct answer ✔✔floor divide How are empty strings assigned in Python? - correct answer ✔✔"" var, str What is 92//3? - correct answer ✔✔ 6 What is 43//4 - correct answer ✔✔ 10 What operator is a short-circuit operator? - correct answer ✔✔&& How is a dictionary defined? - correct answer ✔✔dict. What is the keyword used to determine if a key is in a dictionary? - correct answer ✔✔key How are the items in a dictionary deleted? - correct answer ✔✔del dictionary_name[key] In Python, what is used to structure code? - correct answer ✔✔ Which of the following is the exponent operator? - correct answer ✔✔* Which of the following is the modulus operator? - correct answer ✔✔% What is the correct way of printing the "T" in the string "PYTHON"? - correct answer ✔✔ If my_variable = "food", what is the data type of my_variable? - correct answer ✔✔
What correctly imports the math library? - correct answer ✔✔import math What correctly imports the datetime library? - correct answer ✔✔ What is flow control? - correct answer ✔✔the order in which the program's code executes In Python, what data type do comparisons generate? - correct answer ✔✔ What is an expression after an if statement always followed by? - correct answer ✔✔ What are functions? - correct answer ✔✔ What is this equal to? min(343, 74, 334, 93) - correct answer ✔✔ 74 def value(a,b): return a[:b]. What is: print(value("Notebook",5)? - correct answer ✔✔ What will this return? (min(2,13,3,7)*max(2,-34,4)) abs(-3) - correct answer ✔✔ How would you call the square root from the math module? - correct answer ✔✔import math.sqrt print(1//3) - correct answer ✔✔0 (floor division gets rid of remainders so 0.333 = 0) In Python, what is one function to output content to the display? - correct answer ✔✔ What symbol can be used to comment out one line of code in Python? - correct answer ✔✔# How would you cast the variable a that is equal to "2" to an integer 2? - correct answer ✔✔
What is the keyword used after the try statement to handle exceptions? - correct answer ✔✔ What is the proper way to open a file that you intend to read from? - correct answer ✔✔open("test.txt", r) (r=read) What is the proper way to open a file that you intend to write to? - correct answer ✔✔open("test.txt", w) (w=write) What does import locale as lc do? - correct answer ✔✔ What is not true a recursive function? - correct answer ✔✔Recursion is a way of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call. Why should you not use == to compare two floating point numbers? - correct answer ✔✔a=10 #The value 10 will be stored in the integer variable a......if(a==10): #This will check if the value stored in variable a is equal to 10. If yes it will return a non zero value What does the exit() function from the system module do? - correct answer ✔✔ In Python, the operator != does what? - correct answer ✔✔inequality When input is from the keyboard, what data type does it default to? - correct answer ✔✔ What role does a semicolon ; perform in Python? - correct answer ✔✔the ; as a separator, not a terminator. You can also use them at the end of a line, which makes them look like a statement terminator In Python,the expression 4+3^2-6/3 will output - correct answer ✔✔syntax error (but if 32 = 11)
Which of the expressions produces 144? - correct answer ✔✔ What is the output of print('23'+'7') - correct answer ✔✔ 237 Which of the following is an acceptable Python variable name? - correct answer ✔✔string.int (???) What is the order of precedence for logical operators? (and, or, not) - correct answer ✔✔or, and, not How do you end an infinite loop on windows? - correct answer ✔✔ A group of consecutive statements with the same indentation is called a _________. - correct answer ✔✔block The process of finding and getting rid of programming errors - correct answer ✔✔ num = set([1,1,2,3,3,3,4]) - correct answer ✔✔ x = True - correct answer ✔✔ print(r"\nhello") - correct answer ✔✔\nhello print("\x48\x49!") - correct answer ✔✔HI! (range(6)) - correct answer ✔✔(1,2,3,4,5,6) How do you do an exponent in Python? - correct answer ✔✔x**n What do you call a variable that is the same throughou the whole program? - correct answer ✔✔
Which of the following is an example of an integer? - correct answer ✔✔ Which of the following is an example of a floating point number? - correct answer ✔✔ What is the file format of python files? - correct answer ✔✔ What is the output of a=3, b=5, if a: print(b) else: print (0) - correct answer ✔✔ 5 What is the syntax to use the built in variable pi? - correct answer ✔✔ What is the output of word = "Alabama", word[3]="Z",print (word) - correct answer ✔✔ What is the index of 5 in the array [0,3,5,8] - correct answer ✔✔ For x = (2+2)-(39)(1-1)/12 - correct answer ✔✔ 4 y=0, for x in range(0,5,1): y=y+x - correct answer ✔✔ 10 y=0, for x in range(0,5,1); y=y+x - correct answer ✔✔z=int(y)+x x=0,y=3,n=0, while abs(x-y)>=1: x=x+0.5 n=n+1 - correct answer ✔✔x=2. n= What is the syntax to add an element to a list? - correct answer ✔✔ Which one of these is floor division? - correct answer ✔✔// ___represents an entity in the real world with its identity and behavior. - correct answer ✔✔
What happens if the base condition isn't defined in recursive programs? - correct answer ✔✔ How many arguments can be passed to a function in a single function call? - correct answer ✔✔zero or more Which of the following is not a Python keyword? - correct answer ✔✔"eval" bc it can be used as a variable Which of the following is the proper form of writing a tuple in Python? - correct answer ✔✔tup=(1,2,3,4,5); What is the most accurate form of the constant pi to use in a Python? - correct answer ✔✔ What is the correct way to use math functions? - correct answer ✔✔ What is a tuple? - correct answer ✔✔a sequence that works like a list but is immutable (can't change) What is the function of defining a main? - correct answer ✔✔def What statement is used to end an if statement? - correct answer ✔✔colon: (???) What function key runs the program? - correct answer ✔✔f5 (fn + f5 on mac) What is the proper formatting for creating a dictionary? - correct answer ✔✔dictionary_name={key1:value1, key2:value2..} Which operator has the highest precedence? - correct answer ✔✔** What is the result of 4>5? - correct answer ✔✔false