Python
Column 1 Creating a list To create a new list in Python, use square brackets [] and separate the elements with commas. For example: my_list = [1, 2, 'hello', True]. Lists can contain different data types such as integers, strings or booleans. Creating lists in python List Functions Here are some common list functions and methods in Python that you can use to manipulate and work with lists:
List Methods:
List Comprehensions: List comprehensions are concise ways to create lists using a single line of code. They often involve iterating over an iterable and applying an expression to each element. Example squares = [x ** 2 for x in range(10)] # Creates a list of squares from 0 to 9: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] These functions and methods are fundamental for working with lists in Python. Experimenting with them will help you become more comfortable and proficient in using lists effectively in your code. Selecting List Elements In Python, you can select or access elements from a list using indexing. Lists are zero-indexed, which means that the first element has an index of 0, the second element has an index of 1, and so on. Here are a few ways to select list elements in Python: Remember that attempting to access an index that is out of the range of the list will result in an "IndexError". Always ensure that your indices are within the valid range of the list. Column 2 Operators in Python Python provides a variety of operators for performing different operations. Some common types of operators include arithmetic, assignment, comparison, logical and bitwise operators. Arithmetic operators are used to perform mathematical calculations such as addition (+), subtraction (-), multiplication (*), division (/) etc. Assignment operator (=) is used to assign values to variables. Comparison operators (==, !=, >,< ,>= ,<= ) are used for comparing two values or expressions and return True or False based on the result. Assignment Operators Assignment operators are used to assign values to variables. They combine the assignment operator (=) with another arithmetic or logical operator, such as += (add and assign), -= (subtract and assign), *= (multiply and assign), /= (divide and assign). These operators allow you to perform an operation on a variable while assigning the result back into the same variable in one step. Logical operators Logical operators in Python are used to combine multiple conditions and evaluate the result as either True or False. The three logical operators in Python are 'and', 'or', and 'not'. - The 'and' operator returns True if both conditions on its left and right side are true. - The 'or' operator returns True if at least one of the conditions on its left or right side is true. - The 'not' operator negates a condition, returning False if it was originally true, and vice versa. Numeric comparison operators Numeric comparison operators are used to compare two numeric values in Python. Some commonly used numeric comparison operators include: - Equal to (==): Returns True if the operands on both sides of the operator are equal. - Not equal to (!=): Returns True if the operands on both sides of the operator are not equal. - Greater than (>), Less than (<), Greater than or equal to (>=), and Less than or equal to (<=) : These operators return True or False based on whether one operand is greater, less, greater/equal, or less/equal compared with another. Column 3 Open-source Python packages are important tools. Their powers expand the Python language. Install new packages, such as pandas, by typing pip install pandas in your command terminal. After installing a package, import it. The Working Directory The working directory is where Python reads and saves files by default. An example of a working directory is C://file/path. The os library sets and retrieves the working directory. COMMONLY USED DATA TYPES
Input and Output:
Conditional Statements:
Python Definition Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum in 1991. Python supports multiple paradigms including procedural, object-oriented, and functional programming. It has a large standard library that provides tools for various tasks such as web development, data analysis, machine learning, and more. Some Basics Syntax
HELP Module (Library) python module is simply a '.py' file |