Posts

Course Eleven - Use Lists in Python language

Image
Use Lists in Python language By  ienex Lists are one of the most versatile sequence data types in Python. Each element in a list has a position or index , starting from 0. Python supports several sequence types, but lists and tuples are the most commonly used. Creating Lists A list is created by placing comma-separated values inside square brackets [] . List items do not have to be of the same type : list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5] list3 = ["a", "b", "c", "d"] Accessing List Elements Use square brackets to access elements by their index or a slice of the list: list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7] print("list1[0]:", list1[0]) print("list2[1:5]:", list2[1:5]) Output: list1[0]: physics list2[1:5]: [2, 3, 4, 5] Updating List Elements You can update a single element or a slice of elements . To add new it...

Course Ten - String & variables in python

Image
String & variables in python By  ienex Strings are one of the most commonly used data types in Python. They are easily created by enclosing characters in single ( ' ) or double ( " ) quotes. var1 = 'Hello World!' var2 = "Python Programming" Accessing Values in Strings In Python, characters are treated as strings of length one , so a single character is considered a substring. You can access substrings using square brackets [] : var1 = 'Hello World!' var2 = "Python Programming" print("var1[0]:", var1[0]) print("var2[1:5]:", var2[1:5]) Output: var1[0]: H var2[1:5]: ytho Updating Strings Strings are immutable , so to update a string, you must assign a new value to the variable. You can also concatenate parts of the old string with a new string: var1 = 'Hello World!' print("Updated String:", var1[:6] + 'Python') Output: Updated String: Hello Python Escape Characters Escape c...

Course Nine - Use numbers with Python

Image
Use numbers with Python By  ienex In Python, numeric data types are used to store numeric values. These values are immutable , meaning that changing a value creates a new object in memory rather than modifying the existing one. Creating Numeric Objects Numeric objects are created when a value is assigned to a variable: var1 = 1 var2 = 10 You can also delete numeric objects using the del statement: del var1 del var_a, var_b Numeric Data Types in Python Python supports four primary numeric types: Integer ( int ) : Whole numbers, positive or negative, without a decimal point. Long integer ( long ) : Integers of unlimited size. Denoted with L at the end (preferably uppercase to avoid confusion with the digit 1 ). Floating point ( float ) : Real numbers with a decimal point. Can also be expressed using scientific notation ( 5e2 = 5 × 10² ). Complex numbers ( complex ) : Numbers in the form a + bj , where a is the real part, b is the imaginary part, and j re...

Course Eight - Loops in Python

Image
Loops in Python By  ienex In programming, instructions are generally executed sequentially , one after the other. However, there are situations where we need to repeat a block of instructions multiple times . This is where loops come into play in Python. What is a Loop? A loop is a control structure that allows a set of instructions to be executed repeatedly , based on a condition or over a sequence of items. Python provides several types of loops to handle different scenarios. Types of Loops in Python Loop Type Description while loop Repeats a block of instructions as long as a specific condition is true . The condition is checked before each iteration. for loop Iterates over a sequence or collection of items (like a list, string, or range) for a specific number of times. Nested loops Loops can be placed inside other loops to handle more complex repetitive tasks. Control Instructions for Loops Python provides special statements to control th...

Course Seven - Decision making in Python application Programming

Image
Decision making in Python application Programming By  ienex Decision-making in programming involves evaluating conditions during program execution and taking appropriate actions based on those conditions. In Python, decision-making is typically done using logical expressions that evaluate to either True or False . The program then executes specific code depending on the result. How Python Evaluates Conditions In Python: Any non-zero value is considered True . A zero value or None is considered False . This allows Python to handle a wide range of decision-making scenarios efficiently. Decision-Making Structures in Python Python provides several control structures for decision-making: Statement Description if Evaluates a logical expression and executes a block of code if the expression is True . if ... else Provides alternative actions when the if expression is False . if ... elif ... else Allows multiple conditions to be checked se...

Course Six - Operators in Python

Image
Operators in Python By  ienex Operators are symbols that perform operations on variables or values . For example, in the expression 4 + 5 = 9 , the numbers 4 and 5 are operands, and + is the operator. Python provides several types of operators, including: Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Identity Operators Membership Operators Operator Precedence 1. Arithmetic Operators Arithmetic operators perform basic mathematical operations . Example: a = 21 b = 10 c = 0 c = a + b print("Line 1 - Value of c is", c) c = a - b print("Line 2 - Value of c is", c) c = a * b print("Line 3 - Value of c is", c) c = a / b print("Line 4 - Value of c is", c) c = a % b print("Line 5 - Value of c is", c) a = 2 b = 3 c = a ** b print("Line 6 - Value of c is", c) a = 10 b = 5 c = a // b print("Line 7 - Value of c is", c) ...

Course Five - Transformation models in Python

Image
Transformation models in Python By  ienex In Python, variables are reserved locations in memory used to store values. When you create a variable, Python automatically allocates memory and determines what kind of data it can hold, such as integers, floating-point numbers, or strings. Assigning Values to Variables Variables in Python do not need explicit declaration . Memory is allocated automatically when a value is assigned using the = operator. # Python example counter = 100 # Integer assignment miles = 1000.0 # Floating-point assignment name = "John" # String assignment print(counter) print(miles) print(name) Output: 100 1000.0 John Multiple Assignment Python allows assigning the same value to multiple variables : a = b = c = 1 You can also assign different values to multiple variables at once: a, b, c = 1, 2, "John" Standard Data Types Python supports several standard data types that define how values are stored and manipu...