this is a list of programs i coded myself for understanding python. it contains python fundamentals: for loops, while loops, lists, tuples, string traversing, built-in functions usage, pattern generators.
credits to my comp. science teacher for setting up the questions!
int()
: Converts a string or a number to an integer.float()
: Converts a string or a number to a floating-point number.str()
: Converts an object to a string.input()
: Takes user input as a string.print()
: Prints the specified message to the console.
if
,elif
,else
: Conditional statements for decision-making.while
: Executes a block of code repeatedly as long as a specified condition is true.for
: Iterates over a sequence (that is either a list, tuple, dictionary, string, or range).
math.pow()
(imported frommath
module): Returns the value of x to the power of y.math.pi
(imported frommath
module): Mathematical constant representing the ratio of a circle's circumference to its diameter.
list.append()
: Appends an element to the end of the list.list.pop()
: Removes and returns the last item from the list.list.remove()
: Removes the first occurrence of a specified element from the list.list.index()
: Returns the index of the first occurrence of a specified value.
str.replace()
: Replaces a specified phrase with another specified phrase.str.isupper()
,str.islower()
,str.isspace()
: Checks if all characters in a string are uppercase, lowercase, or whitespace.
dict.keys()
: Returns a view of dictionary keys.dict.values()
: Returns a view of dictionary values.dict.items()
: Returns a view of dictionary items.
statistics.median()
: Computes the median of a sequence of numbers.
break
: Terminates the loop statement and transfers execution to the statement immediately following the loop.
chr()
: Returns a string representing a character whose Unicode code point is the integer.abs()
: Returns the absolute value of a number.
int
: Integer data type.float
: Floating-point data type.str
: String data type.list
: List data type.tuple
: Tuple data type.dict
: Dictionary data type.