• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Exam (elaborations)

C859 Python Syntax Questions and Complete Solutions Graded A+

Document preview thumbnail
Preview 2 out of 6 pages

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 != - Answer: not equal to len() - Answer: returns length title() - Answer: capitalizes first letter of each word islower() - Answer: determines if the string consists of lowercase characters count() - Answer: totals number of times an argument is found within a predefined value format() - Answer: inserts variable data in a string def - Answer: keyword used to create functions def myfunction(): - Answer: syntax for function declaration return - Answer: defines output of a function if age 16: - Answer: creates an if statement else: - Answer: else statement, used in conjunction with if statement or if/elif statement elif age = 16 and age = 18: - Answer: elif statement, used in conjunction with if statement True and False - Answer: False: and operation will always be false unless both sides are true True or False - Answer: True: or operation will always be true unless both sides are false not(True and False) - Answer: True: Boolean not operation will produce the inverse value. 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 myPhone = (877, 435, 7948) - Answer: creates a tuple open('/my_path/my_','r') - Answer: opens a file object for reading open('/my_path/my_','w') - Answer: opens a file object for writing read() - Answer: reads data from open file close() - Answer: closes open file write() - Answer: writes to open file with open('/my_path/my_','r') as f: - Answer: opens a file, performs operations and automatically closes file import math - Answer: imports math module from collections import defaultdict - Answer: imports individual function from a module from csv import reader as scvreader - Answer: mports individual function from a module and assigns it a new name $ pip3 install pytz - Answer: install package through the command line import pytz - Answer: imports a package split() - Answer: string method used to break apart a string and return a list

Content preview

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

Document information

Uploaded on
March 26, 2025
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
YourExamplug
4.1
(74)
Sold
228
Followers
27
Items
18118
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions