Posts

Showing posts from May, 2023

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