Python: Get Started in Minutes!

Python: Get Started in Minutes!

Guide for Beginners to get started with Python programming. Anyone with an interest to learn can start coding!

ยท

6 min read

Hey, future programmers! At this time and age, it's important to learn about one of the most popular languages in the world, used by top-level companies. Created by Guido van Rossum and released in 1991, Python is an advanced, general-purpose programming language, which has a clean syntax that is easy to learn.

Topics we'll cover

  • Basic Concepts ๐Ÿค”

  • Variables & Data types โšฝ๏ธ

  • Operators ๐Ÿ”

  • Conditional Statements ๐Ÿš—

  • Iterative Loops ๐Ÿ•ณ

  • And Mystery Tips... ๐Ÿคซ

Prerequisites

๐Ÿ Download Python - for installing the Python interpreter
๐Ÿ—’๏ธ Download Mu Editor - for writing code in
(If you need help setting up, make sure to comment and reach out)


Let's Start ๐ŸŒฑ

Why Python is Awesome?

Python is known for its simple code styling and its huge range of tools. It allows programmers to write models and programs in less amount of code lines compared to other languages such as C++ or Java.

Known for its high expertise in Web Development (Django & Flask) and a beast in Data Science, it is used by applications like Youtube, Instagram, etc..

Other advantages include:

  • Beginner Friendly

  • Biggest Community with lots of support

  • Great Career in different fields of interest

"Hello World" in Python

Before we go through the awesomeness of Python, let's try it out!

Open Mu Editor, and use the default Python editor mode (which might be prompted) and then, write the following code!

print("Hello, world!")

Click "Run" and save the file. It should output the following:

๐ŸŽ‰ Congrats!
You are now a ๐Ÿ Python programmer!


Basic Concepts ๐Ÿค”

Before diving into more advanced parts of Python, it's important to understand the fundamental concepts that wrap this language around:

  • Syntax & Indentation

    Python has a distinctive way of going around code. It uses a concept of indentation to improve code readability and to define code blocks. Not doing so, will cause syntax errors

  • Inputs

    Take user inputs from the terminal or console by using Python's built-in method input() , which can accept value(s) as a variable

    Eg: x = input("Enter number : ")

  • Comments

    Write notes alongside your code to help yourself and other developers understand what recipe you're cooking!

    Simply use a # and all text on the character's right will be commented out


Variables & Datatypes

Variables are containers to store data or values. They can be anything, ranging from strings to floating point numbers for names to bank balances!

Python provides different types of variables for different purposes. These are called datatypes. Each datatype has its unique properties and usages.

In Python, there are particularly two classifications of datatypes:

  1. Basic Datatypes (Numbers & Strings)

  2. Advanced Datatypes (Lists & Dictionaries)

Basic Datatypes

Basic Datatypes are atomic units, meaning Advanced Datatypes are derived from these. These data types include:

  1. Integer
    Eg: 420, 69, -27, 13, ...

  2. Float
    Eg: 3.14, 3.33333, 2.00, ...

  3. String
    Eg: "Abel", "Blog", "Python", ...

  4. Bool
    Eg: True, False [There are no other values possible]

# Examples for Datatypes in Python

a = 69 # integer
b = 3.14 # float
c = "Abel Roy" # string
d = True # bool

# Print the variables
print(a, b, c, d)
# Find out the type of a variable
print(type(c))

Note:
Python is case-sensitive. Meaning a variable defined m and M is different.

Advanced Datatypes

Advanced Datatypes are derived from basic types, they are ways of storing data values in the form of sets, lists, etc... depending on the usage. There are 4 advanced datatypes:

  1. List
    An ordered collection of data that is mutable

    [1, 2, 3]

  2. Tuple
    An ordered collection of data that is immutable

    (4, 5, 6)

  3. Sets
    An unordered, unique collection of data
    {7, 8, 9}

  4. Dictionaries
    A collection of data in the form of key-value pairs
    {1: "Abel", 2: "Roy"}

# Examples of Advanced Datatypes
li = [1, 2, 3]
tu = (4, 5, 6)
st = {7, 8, 9} # note: values will not repeat in sets
di = {
    1: "Abel",
    69: "Python",
    "Hello": "World"
}

Indexing

To get the value at a current position, you can index them via datatype[index] .
Eg: print(li[1]) -> prints "2"

\(We will learn this in-depth later on)*

Camel casing

By convention variables are often camel-cased, meaning the first letter is small and the next words are all capitalised.
Eg: helloWorld = "Python"


Operators

Python supports 8 different types of operations:

  1. Arithmetic Operators
    + - * / % ** ...

  2. Relational Operators
    < > == >= <= !=

  3. Logical Operations
    and or not

  4. Assignment Operations
    = += -= *= ...

  5. Bitwise Operations
    & | << >> ~

  6. Membership Operations

    in not in

  7. Identity Operations
    is is not

  8. Conditional Operators

    ?:

For more details, try using them between operands!
If you need assistance, here's the code for each operation.

Task:

Create a calculator that can take two values as input and shows the result by performing arithmetic operations


Conditional Statements

Conditions Statements are essential to control the flow of your program. Python has three keywords for the same:

  1. if Statement

    Most basic conditional statement. It depends on a condition and runs the statements only if the condition is true.

  2. else Statement

    Can only be used, if and only if the if statement is present. It works as an escaping operation, which will run only if the if statement failed!

  3. elif Statement

    When there are multiple conditions to be added in a control statement, elif is used. In other languages, besides Python, elif is also referred to as else if

Syntax

if <condition1>:
    <statement1>
elif <condition2>:
    <statement2>
else:
    <statement3>

Guess the Output

a = 10
b = 5
if a == b:
    print("A is equal to b")
else if a > b:
    print("A is greater than b")
else:
    print("A is smaller than b")
# Check the output by running it in Mu Editor

Iterative Loops

Loops are a way to iterate over a set of data values or till a specific value. It is often used as to

Python provides functionalities for 2 different types of loops:

  1. For Loops

    Known for its precise usages. It can run through a list easily.

  2. While Loops

    Simple, but infinite possibilities. It only depends on a condition where if its not met, the loop exits!

Syntax

# For Loop
for <variable> in <dataset>:
    <statement(s)>

# While Loop
while <condition>:
    <statement(s)>

Examples - Try it Out

# For Loop
for i in range(3):
    print(i)

# While Loop
c = 5
while c > 0:
    print(c)
    c -= 1

And here at last... โœจ

To conclude our journey with the basics, here are the tips to improve drastically in the field of Python Programming, enhancing your understanding of the language.

  • Using List & Dict Comprehension

    A Concise way to create lists and dictionaries

  • Utilizing Built-in Functions

    Maximizing to the utmost options, eg, math, random

  • Exploring Python's Ecosystem

    Discovering external libraries and frameworks, eg, numpy, pytorch

  • Embracing Documentation

    The Best Way to be ahead of the competition!

Remember, what we experienced is the tip of the iceberg, the possibilities Python provides are limitless. It depends on each developer to utilize its resources to its utmost capabilities.

Let's Keep Codin'

ย