Python - Part #1

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.

        Note: The pipe sign | represents an alternative.

        x = int(1.5) | x= float( 1) |x = str(1)

        print(x)

        The output will be = 1 | 1.0 | "1"


                String Modification: Are called methods as opposed to functions, they seem the same but

                always belong to a string or any other argument.

                x= "Hi There"

                print(x.upper()) | print(x.lower())

                Output= HI THERE | hi there


ARITHMETIC OPERATORS:

Note: " | " represents separation.

+ | Addition | x + y

-  | Subtraction | x - y

*  | Multiplication | x * y

/   | Division | x / y

% | Modulus | x % y

** | Exponentiation | x ** y

//   | Floor division | x // y


IF STATEMENTS & CONDITIONALS:

Equals | a == b

Not Equals | a != b

Less than | a < b

Greater than | a > b

Less than or equal to | a <= b

Greater than or equal to | a >= b

Example #1 :

We start with "if" which is the principal condition, "elif" continues to other conditions, however, if none of the conditions is true, then we use the "else" statement and it consequently will execute its function.

Therefore this example above will print "x & y are equal".


Example #2 :

The following program is intended to compute if the person who is applying for a loan is eligible to have it, we are going to determine it by using the if statement and the operators "and", "or" & "not".

If the person has a good credit score and high income, the print message will be displayed on the terminal.
If the person does not meet one or neither of the requirements, then the print message won't be displayed.


Output: {nothing}

If the person has either a good credit score or a high income, then the person will be eligible for the loan


Output: You are eligible for a loan

If the person has the two requirements and also has no criminal records, then the person will be eligible for the loan


Output: You are eligible for a loan

Comments

Popular posts from this blog

Object-Oriented Programming (OOP)

Linux Essential Commands

Python - Part #3