Python Syntax Questions and Solutions: A Comprehensive Guide, Exams of Computer Science

A comprehensive overview of python syntax, covering fundamental concepts, data types, operators, control flow, data structures, file handling, and modules. It includes a series of questions and answers, offering a practical approach to learning and understanding python programming.

Typology: Exams

2024/2025

Available from 04/09/2025

Your-Exam-Plug
Your-Exam-Plug 🇺🇸

5

(3)

10K documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C859 Python Syntax Questions and
Complete Solutions Graded A+
var1, var2, var3 = 1, 2, 3 - Answer: multiple variable assignment
12 - Answer: integer
1.2 - Answer: float
'twelve' - Answer: string
"twelve" - Answer: string
True or False - Answer: Boolean value
type() - Answer: determines type of an object (integer, boolean, etc)
int() - Answer: converts to integer object
float() - Answer: converts to float object
str() - Answer: converts to string object
print() - Answer: displays a message
+ - Answer: addition (integer) or concatenation (string)
- - Answer: subtraction
pf3
pf4
pf5

Partial preview of the text

Download Python Syntax Questions and Solutions: A Comprehensive Guide and more Exams Computer Science in PDF only on Docsity!

C859 Python Syntax Questions and

Complete Solutions Graded A+

var1, var2, var3 = 1, 2, 3 - Answer: multiple variable assignment 12 - Answer: integer 1.2 - Answer: float 'twelve' - Answer: string "twelve" - Answer: string True or False - Answer: Boolean value type() - Answer: determines type of an object (integer, boolean, etc) int() - Answer: converts to integer object float() - Answer: converts to float object str() - Answer: converts to string object print() - Answer: displays a message

    • Answer: addition (integer) or concatenation (string)
    • Answer: subtraction

** - Answer: power of % - Answer: modulus, remainder / - Answer: division, always results in float // - Answer: division, always results in integer = - Answer: assignment operator += - Answer: reassignment operator, adds -= - Answer: reassignment operator, subtracts *= - Answer: reassignment operator, multiples /= - Answer: reassignment operator, divides < - Answer: less than

  • Answer: greater than <= - Answer: less than or equal to = - Answer: greater than or equal to == - Answer: equal to

myNumbers = [1, 4.8, 7, 9.2, 3, 0] - Answer: creates a list mylist[0] - Answer: accesses first element from a list mylist[-1] - Answer: accesses last element from a list mylist[1:3] - Answer: slices list including second and third element mylist[:3] - Answer: slices list beginning with first element and including through the third element. Index position 3 is not included in selection. mylist[3:] - Answer: slices list beginning with fourth element and include remainder of the list 9.2 in myNumbers - Answer: looks for a match and returns Boolean value 9.2 not in myNumbers - Answer: ensures a match does not exist in list len() - Answer: counts items in list max() - Answer: returns greatest element of list min() - Answer: returns smallest element of list sorted() - Answer: returns copy of list ordered smallest to largest sorted(listname, reverse=True) - Answer: returns copy of list ordered largest to smallest sum() - Answer: returns total sum of list values

append() - Answer: adds new value to end of list pop() - Answer: removes last item from a list pop(1) - Answer: removes second item from a list join() - Answer: joins values from a list using a defined separator set() - Answer: creates a set, or a list that contains unique items add() - Answer: adds value to set discard() - Answer: removes value from set, if found for city in cities: - Answer: iterates over items within a list range() - Answer: defines a range of numbers while temp >= 32: - Answer: iterates a set of commands as long as the condition remains true, stopping when the condition becomes false break - Answer: loop command that stops iteration prematurely studentGrades = { 'Orfu': 83, 'Bismark': 98, 'Igor': 72} - Answer: entries are added in key/value pairs if 'key' in dictionary: - Answer: verifies if key exists in dictionary get() - Answer: looks up value by key