Docsity

C859 Python Syntax exams with verified solutions 2026/2027 study set, Exams of Computer Networks

Partial preview of the text

Download C859 Python Syntax exams with verified solutions 2026/2027 study set and more Exams Computer Networks in PDF only on Docsity!

C859 Python Syntax exams with verified

solutions 2026/2027 study set

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

subtraction

power of % modulus, remainder / division, always results in float // division, always results in integer = assignment operator += reassignment operator, adds

- = reassignment operator, subtracts *= reassignment operator, multiples /= reassignment operator, divides < less than > greater than <= less than or equal to >= greater than or equal to == equal to !=

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

pop(1) removes second item from a list join() joins values from a list using a defined separator set() creates a set, or a list that contains unique items add() adds value to set discard() removes value from set, if found for city in cities: iterates over items within a list range() defines a range of numbers while temp >= 32: iterates a set of commands as long as the condition remains true, stopping when the condition becomes false break loop command that stops iteration prematurely studentGrades = { 'Orfu': 83, 'Bismark': 98, 'Igor': 72} entries are added in key/value pairs if 'key' in dictionary: verifies if key exists in dictionary get() looks up value by key myPhone = (877, 435, 7948) creates a tuple open('/my_path/my_file.txt','r') opens a file object for reading open('/my_path/my_file.txt','w') opens a file object for writing