Professional Documents
Culture Documents
Comparison Operators: Python Hello World! Variable Data Manipulation
Comparison Operators: Python Hello World! Variable Data Manipulation
Comparison Operators: Python Hello World! Variable Data Manipulation
Data Types
Initializing the string
Compound Assignment Operators Use single or double quotes to initialize a string.
Data types categorize data and specify the operations allowed on it.
Add and Assign x+=y text = "Hello, World!"
• int: Integer values (5, 0, -1, etc.)
• float: Floating-point values (2.33333, -2500.001, 20.0, etc.) Divide and assign x/=y
Accessing the characters in a string
• str: String values (educative, python, etc.) Integer divide and assign x//=y Use indexing to access individual characters.
first_char = text[0] # Accesses 'H'
Runtime Errors
Function • islower(): Checks if all characters are lowercase
• isupper(): Checks if all characters are uppercase
Errors that occur during execution (e.g., dividing by zero)
A function is a reusable block of code that performs a specific task
a = 10
or a set of related tasks. b = 0
result = a / b # Division by zero
Syntax of a Function Methods related to case change
def function_name(parameters):
• lower(): Converts all characters to lowercase Logical Errors
# Function body • upper(): Converts all characters to uppercase The code runs without crashing but produces incorrect results.
# ...
return result • title(): Converts the first character of each word to side_length = 5
uppercase # Incorrect formula for calculating the area of a square (uses π
• def: Keyword to define a function r^2)
area = 3.14 * (side_length ** 2)
• function_name: Name of the function print("Area of the square:", area)
• parameters: Input values to the function Search-related methods
• find(): Returns the index of the first occurrence
• return: Keyword to return a result (optional)
• count(): Returns the number of occurrences
Note: A function body comprises a set of instructions that compute the result • startswith(): Checks if the string starts with a
based on the input parameters. Explore the Fundamentals of Python
specified prefix
programming with the best course for you!
• endswith(): Checks if the string ends with a specified
suffix
Function Calls
result = function_name(arguments)