










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











































Indentation in Python - CORRECT ANSWER- Python uses indentation (spaces or tabs at the start of a line) to define code blocks instead of braces. Consistent indentation is required for structures like if statements, loops, and function definitions. Variable in Python - CORRECT ANSWER-A variable is a named reference to a value in memory. You create one by simply assigning a value to a name using =. Basic data types in Python - CORRECT ANSWER-Important built-in data types include Integer (int), Floating-point (float), String (str), Boolean (bool), and NoneType. Integer in Python - CORRECT ANSWER-Whole numbers (e.g. 42, - 5). Floating-point in Python - CORRECT ANSWER- Decimal numbers (e.g. 3.14, 0.5).
String in Python - CORRECT ANSWER-Text sequences in quotes (e.g. 'Hello'). Boolean in Python - CORRECT ANSWER-Truth values True or False. NoneType in Python - CORRECT ANSWER-The special value None indicating 'no value.' Type checking in Python - CORRECT ANSWER- You can use the type() function to check an object's type. For example, type(42) returns . Type conversion in Python - CORRECT ANSWER-Use Python's built-in conversion functions like int(), float(), str(), and bool(). int() function - CORRECT ANSWER-Converts a string to an integer. For example, int('123') converts '123' to 123. str() function - CORRECT ANSWER-Converts a number to a string. For example, str(123) converts 123 to '123'.
Python's built-in documentation - CORRECT ANSWER-Can be accessed using the help() function. Dynamic typing in Python - CORRECT ANSWER- Python is dynamically typed, meaning you don't declare types explicitly. Reassigning variables in Python - CORRECT ANSWER-A variable can refer to data of any type and can be reassigned to a different type later. Common advice for D522 - CORRECT ANSWER- Mastering core Python basics, doing all Zybooks labs and quizzes, and practicing coding exercises. Fundamental data types and structures in Python
Floor Division - CORRECT ANSWER-It divides two numbers and returns the largest integer less than or equal to the result. Example of Floor Division - CORRECT ANSWER- 17 // 5 evaluates to 3 because 17/5 is 3.4 and floor division drops the fractional part. Negative Floor Division Example - CORRECT ANSWER--5 // 2 gives - 3 (since - 2.5 floored is - 3). Modulo Operator (%) - CORRECT ANSWER-The % operator computes the remainder of a division. Example of Modulo - CORRECT ANSWER-7 % 3 equals 1 (since 7 divided by 3 has remainder 1). Even Divisibility Check - CORRECT ANSWER-x % 2 == 0 checks if x is even. Cycling Through Values - CORRECT ANSWER- Using i % 7 to wrap an index every 7 elements. Leap Year Determination - CORRECT ANSWER- year % 4 checks if a year is a leap year.
Example of String Concatenation - CORRECT ANSWER-"Hello, " + "world!" results in "Hello, world!". Formatted Strings - CORRECT ANSWER-You can use f-strings for concatenation and interpolation. TypeError in Concatenation - CORRECT ANSWER-Trying to concatenate a string with an integer will raise a TypeError. Escape Sequences - CORRECT ANSWER- Special characters can be included using escape sequences. Newline Escape Sequence - CORRECT ANSWER-\n represents a newline. Tab Escape Sequence - CORRECT ANSWER-\t represents a tab. Including Quotes in Strings - CORRECT ANSWER-Use " for double quotes in double- quoted strings.
Multi-line Strings - CORRECT ANSWER-Use triple quotes ("""...""" or '''...''') to preserve line breaks. List in Python - CORRECT ANSWER-An ordered, mutable collection of items defined with square brackets. Accessing List Elements - CORRECT ANSWER- Elements can be accessed by index (zero-based). Common List Operations - CORRECT ANSWER- Append an item, remove an item, length of list, and slicing. Tuple in Python - CORRECT ANSWER-An ordered, immutable collection of items typically defined with parentheses. Key Difference Between Tuple and List - CORRECT ANSWER-A tuple cannot be changed (no item assignment or append). Tuple - CORRECT ANSWER-A tuple is used to ensure a sequence of values should not be modified and can be used as keys in dictionaries.
is operator - CORRECT ANSWER-The is operator checks for identity, determining if two references point to the same object in memory. islower() method - CORRECT ANSWER-The islower() method checks if all alphabetic letters in a string are lowercase. isupper() method - CORRECT ANSWER-The isupper() method checks if all alphabetic letters in a string are uppercase. Membership Test - CORRECT ANSWER-A membership test checks if an element is present in a collection, e.g., if x in ids. Union Operation - CORRECT ANSWER-The union operation combines two sets, returning a set with all unique elements from both. Intersection Operation - CORRECT ANSWER- The intersection operation returns a set of elements common to both sets.
Difference Operation - CORRECT ANSWER-The difference operation returns a set of elements in the first set but not in the second. Accessing Tuple Elements - CORRECT ANSWER-Accessing elements of a tuple is done in the same way as with lists, using indexing. Creating a Set - CORRECT ANSWER-You can create a set with curly braces or the set() constructor, e.g., ids = {101, 102, 103}. Removing a Key from Dictionary - CORRECT ANSWER-To remove a key from a dictionary, use del student['city'] or the pop method. Adding/Updating Dictionary Entries - CORRECT ANSWER-You can add or update entries in a dictionary using the syntax student['key'] = value. Accessing Dictionary Values - CORRECT ANSWER-Values in a dictionary can be accessed by their associated keys, e.g., student['name'].
greet function - CORRECT ANSWER-Defines a function that takes one parameter name and returns a greeting string. return statement - CORRECT ANSWER-Specifies the value that a function call will produce; it exits the function immediately and yields the given value to the caller. print() - CORRECT ANSWER-Outputs to the console and returns None; it does not give a value back to the caller. parameters - CORRECT ANSWER-Variable names in a function definition that specify what inputs the function expects. arguments - CORRECT ANSWER-The actual values provided to the parameters when calling the function. default parameter values - CORRECT ANSWER- Allows a function to be called without explicitly providing that argument; if omitted, the default is used.
scope - CORRECT ANSWER-Refers to the region of the code where a variable is visible/accessible. local variable - CORRECT ANSWER-Defined inside a function and exists only within that function's scope. global variable - CORRECT ANSWER-Defined at the top level of a module and can be accessed by any code in that module. TypeError - CORRECT ANSWER-An error raised by Python when the wrong number of arguments is passed to a function. greet('Alice') - CORRECT ANSWER-Executes the greet function with 'Alice' as the argument for name. add function - CORRECT ANSWER-Defines a function that takes two parameters and returns their sum. result = add(5, 3) - CORRECT ANSWER-Stores the return value of the add function when called with arguments 5 and 3.
by parentheses and passing any required arguments. message = f'Hello, {name}!' - CORRECT ANSWER-An example of using an f-string to create a greeting message in the greet function. function arguments - CORRECT ANSWER- Values passed into a function when it is called, which can be used within the function. pass by value - CORRECT ANSWER-A method of passing arguments where a copy of the value is passed, preventing modification of the original. pass by reference - CORRECT ANSWER-A method of passing arguments where a reference to the original object is passed, allowing modification of the original. lambda function - CORRECT ANSWER-An anonymous, small function defined with the lambda keyword that can take any number of arguments but has only one expression.
mutable type - CORRECT ANSWER-A data type in Python that can be changed after it is created, such as lists and dictionaries. immutable type - CORRECT ANSWER-A data type in Python that cannot be changed after it is created, such as integers, floats, strings, and tuples. get_stats function - CORRECT ANSWER-A function that returns multiple values (total, count, average) by returning a tuple. open() function - CORRECT ANSWER-A built-in function in Python used to open a file for reading or writing. custom functions - CORRECT ANSWER- Functions created by the programmer to perform specific tasks, as opposed to built-in functions. pow function - CORRECT ANSWER-A built-in function that calculates the power of a number, taking two arguments: the base and the exponent.
read mode - CORRECT ANSWER-The mode 'r' used with open() to read the contents of a file. context manager - CORRECT ANSWER-A construct that ensures resources are properly managed, such as automatically closing a file after its block is executed. readlines() method - CORRECT ANSWER-A method that reads all lines from a file and returns them as a list. iterating over file object - CORRECT ANSWER-A method to read a file line by line, which is memory-efficient. write mode - CORRECT ANSWER-The mode 'w' used with open() to write to a file, which overwrites the file or creates a new one. append mode - CORRECT ANSWER-The mode 'a' used with open() to add content to the end of a file without erasing existing content. write() method - CORRECT ANSWER-A method that writes a string to a file.
newline character - CORRECT ANSWER-A character used to indicate the end of a line, represented as '\n'. writelines() method - CORRECT ANSWER-A method that writes a list of strings to a file. text mode - CORRECT ANSWER-The default mode for opening files, which treats the file as text and expects a specific encoding. binary mode - CORRECT ANSWER-A mode for opening files that treats the file as a binary stream, reading and writing bytes. FileNotFoundError - CORRECT ANSWER-An exception raised when trying to open a file that does not exist. try/except - CORRECT ANSWER-A construct used to handle exceptions in Python, allowing the program to continue running after an error. os.path.exists() - CORRECT ANSWER-A method to check if a file exists before trying to open it.