Posts

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...

Course Four - The basic structure of the Python language

Image
The Basic Structure of Python By ienex Python is a versatile programming language with similarities to Perl, C, and Java , but it has its own unique features and syntax that make it simpler and more readable. Writing Your First Python Program Python allows you to write programs in two primary ways: interactive programming and scripting . 1. Interactive Programming In interactive mode, you can start the Python interpreter without passing a script file: $ python Python 2.4.3 (#1, Nov 11 2010, 13:34:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Type the following command: >>> print("Hello, Python!") The output will be: Hello, Python! Note: In older versions of Python (like 2.x), print statements may not require parentheses. 2. Scripting You can also write Python programs as script files with a .py extension. Example: # test.py print(...

Course Three - Python language Environment

Image
Python language Environment By ienex Python is a versatile programming language available on all major operating systems , including Linux, macOS, and Windows. Before you start coding, it’s important to set up a local Python environment on your device. Supported Platforms Python can be installed on a wide variety of platforms, including: Unix-based systems: Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX Windows: Windows 9x, NT, 2000, Windows CE macOS: Intel, PPC, 68K Other systems: OS/2, DOS, PalmOS, Nokia mobile phones, Acorn/RISC OS, BeOS, Amiga, VMS/OpenVMS, QNX, VxWorks, Psion To check if Python is already installed, open a terminal or command prompt and type: python This will display the installed Python version, if any. Downloading Python The official Python website, python.org , provides: Source code Binaries for different operating systems Documentation in HTML and PDF Download the version appropriate for your system. If a precompiled b...