Posts

Showing posts from April, 2022

Python - Part #3

Image
What is a loop and why do we use it? A loop is a repetition of a process that is iterated over and over as long as the condition is true or until it is intentionally broken. It is highly useful because it massively reduces the repetition of the code and increases its efficiency. Note: The hash " # " represents the comments which do not alter the code. WHILE LOOPS: Example: x = 1 # Variable declaration while x <= 5:     print(x)     x += 1 Because 1 is less than 5, my boolean condition is true, or in other words: as long as 1 is less than 5 run the program, however, I am adding one to the number each time the program is repeated, so it will automatically stop as soon as the boolean condition is not true anymore. Output:                >> 1                >> 2                >> 3         ...

Python - Part #2

Image
DATA COLLECTION There are four built-in collections of data types in Python, each one with different qualities for particular purposes. LISTS: - Lists are used to store multiple items in a single variable and are created using square brackets [ ]. - List items can be ordered, they are changeable, allow duplicate values, and can contain any data type. - List items are indexed, the first item has index [0], the second item has index [1], and so on. - " : " colon is used inside the index as a range. - To check the type of list we are using we write print (type(list_name)) Example #1: numbers = ["1", "2", "3"] print(numbers[0]) Output:          >> 1 Example #2: list1 = ["letter", 1.4, True, False, "name", 17] print(list1[1:4]) Output:          >>  [1.4, True, False] TUPLES: Tuples are used to store multiple items in a single variable, however, they are a collection that is ordered and unchangeable. As opposed to the li...

Python - Part #1

Image
Brief Definition: Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. It's widely used for data structures, app development, scripting, etc. It's an outstanding programming language because its syntax emphasizes readability to make it more understandable for the users. This article will contain Python introductory essentials. DATA TYPES:   In order for the Python interpreter to understand numbers or letters we use the "Data Types" which are a classification of built-in words that can store mathematical numeric values and strings, each one is different and has its logical purpose. Below are listed the most used ones: Strings: Holds letters (str) | x = "Hello world" Integers: Holds whole numbers (int) | x= 1 Float: Holds short decimals (float) | x = 1.5 Boolean: Holds either True or False statements (bool) I x = True (or False)           Casting: Used to temporarily assign different datatypes.    ...