CORE CONCEPTS FOR PYTHON IT AUTOMATION (WGU D522)
QUESTIONS WITH COMPLETE ANSWERS
Indentation in Python - vc vc vc
ansPython uses indentation (spaces or tabs at the start of a line) to define code blocks i
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
nstead of braces. Consistent indentation is required for structures like if statements, loop
vc vc vc vc vc vc vc vc vc vc vc vc
s, and function definitions.
vc vc vc
Variable in Python - vc vc vc
ansA variable is a named reference to a value in memory. You create one by simply assi
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
gning a value to a name using =.
vc vc vc vc vc vc vc
Basic data types in Python - ansImportant built-
vc vc vc vc vc vc vc
in data types include Integer (int), Floating-
vc vc vc vc vc vc
point (float), String (str), Boolean (bool), and NoneType.
vc vc vc vc vc vc vc
Integer in Python - ansWhole numbers (e.g. 42, -5).
vc vc vc vc vc vc vc vc
Floating-point in Python - ansDecimal numbers (e.g. 3.14, 0.5). vc vc vc vc vc vc vc vc
String in Python - ansText sequences in quotes (e.g. 'Hello').
vc vc vc vc vc vc vc vc vc
Boolean in Python - ansTruth values True or False.
vc vc vc vc vc vc vc vc
NoneType in Python - ansThe special value None indicating 'no value.'
vc vc vc vc vc vc vc vc vc vc
Type checking in Python -
vc vc vc vc
ansYou can use the type() function to check an object's type. For example, type(42) retu
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
rns <class 'int'>.
vc vc
Type conversion in Python - ansUse Python's built-
vc vc vc vc vc vc vc
in conversion functions like int(), float(), str(), and bool().
vc vc vc vc vc vc vc vc
int() function -
vc vc
ansConverts a string to an integer. For example, int('123') converts '123' to 123.
vc vc vc vc vc vc vc vc vc vc vc vc vc
str() function -
vc vc
ansConverts a number to a string. For example, str(123) converts 123 to '123'.
vc vc vc vc vc vc vc vc vc vc vc vc vc
Operators in Python - vc vc vc
ansOperators are symbols that perform operations on values, including arithmetic and c
vc vc vc vc vc vc vc vc vc vc vc vc
omparison operators. vc
,Arithmetic operators in Python - ansInclude + (addition), -
vc vc vc vc vc vc vc vc
(subtraction), * (multiplication), / (division), // (floor division),
vc vc vc vc vc vc vc vc vc
% (modulus), and ** (exponentiation).
vc vc vc vc
Comparison operators in Python - ansInclude == (equal to), != (not equal), <, <=, >, >=.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Common pitfall in Python - vc vc vc vc
ansUsing = instead of == in a condition, which causes a syntax error.
vc vc vc vc vc vc vc vc vc vc vc vc vc
// operator in Python - ansThe // operator is the floor division operator.
vc vc vc vc vc vc vc vc vc vc vc vc
Reading from files in Python - ansInvolves opening a file and counting lines.
vc vc vc vc vc vc vc vc vc vc vc vc
Python's built-in documentation - ansCan be accessed using the help() function.
vc vc vc vc vc vc vc vc vc vc
Dynamic typing in Python - vc vc vc vc
ansPython is dynamically typed, meaning you don't declare types explicitly.
vc vc vc vc vc vc vc vc vc vc
Reassigning variables in Python - vc vc vc vc
ansA variable can refer to data of any type and can be reassigned to a different type late
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
r.
Common advice for D522 - vc vc vc vc
ansMastering core Python basics, doing all Zybooks labs and quizzes, and practicing co
vc vc vc vc vc vc vc vc vc vc vc vc vc
ding exercises.vc
Fundamental data types and structures in Python - vc vc vc vc vc vc vc
ansInclude strings, lists, tuples, sets, and dictionaries.
vc vc vc vc vc vc vc
Example of improper indentation - vc vc vc vc
ansAn improperly indented line will cause an IndentationError or unexpected behavior.
vc vc vc vc vc vc vc vc vc vc vc
Floor Division - vc vc
ansIt divides two numbers and returns the largest integer less than or equal to the result.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Example of Floor Division - ans17 //
vc vc vc vc vc vc
5 evaluates to 3 because 17/5 is 3.4 and floor division drops the fractional part.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Negative Floor Division Example - ans-5 // 2 gives -3 (since -2.5 floored is -3).
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Modulo Operator (%) - ansThe % operator computes the remainder of a division.
vc vc vc vc vc vc vc vc vc vc vc vc
Example of Modulo - ans7 % 3 equals 1 (since 7 divided by 3 has remainder 1).
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Even Divisibility Check - ansx % 2 == 0 checks if x is even.
vc vc vc vc vc vc vc vc vc vc vc vc vc
, Cycling Through Values - ansUsing i % 7 to wrap an index every 7 elements.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Leap Year Determination - ansyear % 4 checks if a year is a leap year.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Modulo with Negative Numbers -
vc vc vc vc
ansPython's result will have the same sign as the divisor.
vc vc vc vc vc vc vc vc vc vc
Logical Operators in Python - ansLogical operators combine or modify boolean values.
vc vc vc vc vc vc vc vc vc vc vc
Logical AND - ansand returns True if both operands are True.
vc vc vc vc vc vc vc vc vc vc
Logical OR - ansor returns True if at least one operand is True.
vc vc vc vc vc vc vc vc vc vc vc vc
Logical NOT - ansnot negates a boolean value.
vc vc vc vc vc vc vc
Short-Circuit Evaluation - vc vc
ansIn (expr1 and expr2), expr2 is only evaluated if expr1 is True.
vc vc vc vc vc vc vc vc vc vc vc vc
String Concatenation - ansJoining strings end-to-end using the + operator.
vc vc vc vc vc vc vc vc vc
Example of String Concatenation - ans"Hello, " + "world!" results in "Hello, world!".
vc vc vc vc vc vc vc vc vc vc vc vc
Formatted Strings - ansYou can use f-strings for concatenation and interpolation.
vc vc vc vc vc vc vc vc vc vc
TypeError in Concatenation - vc vc vc
ansTrying to concatenate a string with an integer will raise a TypeError.
vc vc vc vc vc vc vc vc vc vc vc vc
Escape Sequences - ansSpecial characters can be included using escape sequences.
vc vc vc vc vc vc vc vc vc vc
Newline Escape Sequence - ans\n represents a newline.
vc vc vc vc vc vc vc
Tab Escape Sequence - ans\t represents a tab.
vc vc vc vc vc vc vc
Including Quotes in Strings - ansUse \" for double quotes in double-quoted strings.
vc vc vc vc vc vc vc vc vc vc vc vc
Multi-line Strings - ansUse triple quotes ("""...""" or '''...''') to preserve line breaks.
vc vc vc vc vc vc vc vc vc vc vc vc
List in Python - ansAn ordered, mutable collection of items defined with square brackets.
vc vc vc vc vc vc vc vc vc vc vc vc vc
Accessing List Elements - ansElements can be accessed by index (zero-based).
vc vc vc vc vc vc vc vc vc vc
Common List Operations - vc vc vc
ansAppend an item, remove an item, length of list, and slicing.
vc vc vc vc vc vc vc vc vc vc vc
QUESTIONS WITH COMPLETE ANSWERS
Indentation in Python - vc vc vc
ansPython uses indentation (spaces or tabs at the start of a line) to define code blocks i
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
nstead of braces. Consistent indentation is required for structures like if statements, loop
vc vc vc vc vc vc vc vc vc vc vc vc
s, and function definitions.
vc vc vc
Variable in Python - vc vc vc
ansA variable is a named reference to a value in memory. You create one by simply assi
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
gning a value to a name using =.
vc vc vc vc vc vc vc
Basic data types in Python - ansImportant built-
vc vc vc vc vc vc vc
in data types include Integer (int), Floating-
vc vc vc vc vc vc
point (float), String (str), Boolean (bool), and NoneType.
vc vc vc vc vc vc vc
Integer in Python - ansWhole numbers (e.g. 42, -5).
vc vc vc vc vc vc vc vc
Floating-point in Python - ansDecimal numbers (e.g. 3.14, 0.5). vc vc vc vc vc vc vc vc
String in Python - ansText sequences in quotes (e.g. 'Hello').
vc vc vc vc vc vc vc vc vc
Boolean in Python - ansTruth values True or False.
vc vc vc vc vc vc vc vc
NoneType in Python - ansThe special value None indicating 'no value.'
vc vc vc vc vc vc vc vc vc vc
Type checking in Python -
vc vc vc vc
ansYou can use the type() function to check an object's type. For example, type(42) retu
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
rns <class 'int'>.
vc vc
Type conversion in Python - ansUse Python's built-
vc vc vc vc vc vc vc
in conversion functions like int(), float(), str(), and bool().
vc vc vc vc vc vc vc vc
int() function -
vc vc
ansConverts a string to an integer. For example, int('123') converts '123' to 123.
vc vc vc vc vc vc vc vc vc vc vc vc vc
str() function -
vc vc
ansConverts a number to a string. For example, str(123) converts 123 to '123'.
vc vc vc vc vc vc vc vc vc vc vc vc vc
Operators in Python - vc vc vc
ansOperators are symbols that perform operations on values, including arithmetic and c
vc vc vc vc vc vc vc vc vc vc vc vc
omparison operators. vc
,Arithmetic operators in Python - ansInclude + (addition), -
vc vc vc vc vc vc vc vc
(subtraction), * (multiplication), / (division), // (floor division),
vc vc vc vc vc vc vc vc vc
% (modulus), and ** (exponentiation).
vc vc vc vc
Comparison operators in Python - ansInclude == (equal to), != (not equal), <, <=, >, >=.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Common pitfall in Python - vc vc vc vc
ansUsing = instead of == in a condition, which causes a syntax error.
vc vc vc vc vc vc vc vc vc vc vc vc vc
// operator in Python - ansThe // operator is the floor division operator.
vc vc vc vc vc vc vc vc vc vc vc vc
Reading from files in Python - ansInvolves opening a file and counting lines.
vc vc vc vc vc vc vc vc vc vc vc vc
Python's built-in documentation - ansCan be accessed using the help() function.
vc vc vc vc vc vc vc vc vc vc
Dynamic typing in Python - vc vc vc vc
ansPython is dynamically typed, meaning you don't declare types explicitly.
vc vc vc vc vc vc vc vc vc vc
Reassigning variables in Python - vc vc vc vc
ansA variable can refer to data of any type and can be reassigned to a different type late
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
r.
Common advice for D522 - vc vc vc vc
ansMastering core Python basics, doing all Zybooks labs and quizzes, and practicing co
vc vc vc vc vc vc vc vc vc vc vc vc vc
ding exercises.vc
Fundamental data types and structures in Python - vc vc vc vc vc vc vc
ansInclude strings, lists, tuples, sets, and dictionaries.
vc vc vc vc vc vc vc
Example of improper indentation - vc vc vc vc
ansAn improperly indented line will cause an IndentationError or unexpected behavior.
vc vc vc vc vc vc vc vc vc vc vc
Floor Division - vc vc
ansIt divides two numbers and returns the largest integer less than or equal to the result.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Example of Floor Division - ans17 //
vc vc vc vc vc vc
5 evaluates to 3 because 17/5 is 3.4 and floor division drops the fractional part.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Negative Floor Division Example - ans-5 // 2 gives -3 (since -2.5 floored is -3).
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Modulo Operator (%) - ansThe % operator computes the remainder of a division.
vc vc vc vc vc vc vc vc vc vc vc vc
Example of Modulo - ans7 % 3 equals 1 (since 7 divided by 3 has remainder 1).
vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Even Divisibility Check - ansx % 2 == 0 checks if x is even.
vc vc vc vc vc vc vc vc vc vc vc vc vc
, Cycling Through Values - ansUsing i % 7 to wrap an index every 7 elements.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Leap Year Determination - ansyear % 4 checks if a year is a leap year.
vc vc vc vc vc vc vc vc vc vc vc vc vc vc
Modulo with Negative Numbers -
vc vc vc vc
ansPython's result will have the same sign as the divisor.
vc vc vc vc vc vc vc vc vc vc
Logical Operators in Python - ansLogical operators combine or modify boolean values.
vc vc vc vc vc vc vc vc vc vc vc
Logical AND - ansand returns True if both operands are True.
vc vc vc vc vc vc vc vc vc vc
Logical OR - ansor returns True if at least one operand is True.
vc vc vc vc vc vc vc vc vc vc vc vc
Logical NOT - ansnot negates a boolean value.
vc vc vc vc vc vc vc
Short-Circuit Evaluation - vc vc
ansIn (expr1 and expr2), expr2 is only evaluated if expr1 is True.
vc vc vc vc vc vc vc vc vc vc vc vc
String Concatenation - ansJoining strings end-to-end using the + operator.
vc vc vc vc vc vc vc vc vc
Example of String Concatenation - ans"Hello, " + "world!" results in "Hello, world!".
vc vc vc vc vc vc vc vc vc vc vc vc
Formatted Strings - ansYou can use f-strings for concatenation and interpolation.
vc vc vc vc vc vc vc vc vc vc
TypeError in Concatenation - vc vc vc
ansTrying to concatenate a string with an integer will raise a TypeError.
vc vc vc vc vc vc vc vc vc vc vc vc
Escape Sequences - ansSpecial characters can be included using escape sequences.
vc vc vc vc vc vc vc vc vc vc
Newline Escape Sequence - ans\n represents a newline.
vc vc vc vc vc vc vc
Tab Escape Sequence - ans\t represents a tab.
vc vc vc vc vc vc vc
Including Quotes in Strings - ansUse \" for double quotes in double-quoted strings.
vc vc vc vc vc vc vc vc vc vc vc vc
Multi-line Strings - ansUse triple quotes ("""...""" or '''...''') to preserve line breaks.
vc vc vc vc vc vc vc vc vc vc vc vc
List in Python - ansAn ordered, mutable collection of items defined with square brackets.
vc vc vc vc vc vc vc vc vc vc vc vc vc
Accessing List Elements - ansElements can be accessed by index (zero-based).
vc vc vc vc vc vc vc vc vc vc
Common List Operations - vc vc vc
ansAppend an item, remove an item, length of list, and slicing.
vc vc vc vc vc vc vc vc vc vc vc