avatarM Mahfujur Rahman, PhD

Summary

The provided content serves as a comprehensive guide to learning Python programming, offering insights into its syntax, data types, control flow, functions, classes, and modules, while emphasizing its simplicity and widespread use in the industry.

Abstract

The web content titled "Learn Python in One Day" is an extensive tutorial designed for individuals with varying levels of programming expertise, from beginners to those with intermediate knowledge. It introduces Python as a favored language at Google and other tech giants, highlighting its readability and ease of learning. The guide covers fundamental concepts such as variables, conditional statements, data types, mathematical operations, loops, and error handling with try-except blocks. It also delves into more advanced topics, including the creation and usage of functions, recursive functions, classes, inheritance, and the implementation of *args and **kwargs for variable argument lists. Additionally, the tutorial explains the practical use of lists and dictionaries for data manipulation and demonstrates how to create and utilize modules for organized and reusable code. The author encourages regular practice and offers to address further advanced Python topics based on reader feedback, concluding with an invitation to follow for future Python challenges and a call to support the author's work on Medium and other platforms.

Opinions

  • The author, M Mahfujur Rahman, expresses a preference for Python due to its simplicity, clear syntax, and strong community support, particularly in the field of machine learning.
  • Python's versatility and popularity are underscored by its use in major companies like Google, Facebook, NASA, Amazon, and YouTube.
  • The tutorial promotes the idea that learning Python can be efficient, suggesting that even the basics can be mastered in a single day.
  • The author believes in the importance of practice, quoting Bruce Lee to emphasize that regular practice leads to skillfulness and proficiency in programming.
  • There is an opinion that using inheritance in Python leads to more organized and structured code, reducing code repetition and effort in class creation.
  • The use of Jupyter notebooks is recommended for writing and testing Python code, with a mention of Google Colab as a convenient platform for this purpose.
  • The author values reader engagement and feedback, offering to expand the tutorial based on the audience's needs and interests.
  • A call to support the author through Medium membership, Ko-fi, or Paypal donations indicates the author's commitment to providing valuable content and the desire for recognition and compensation for their efforts.

Python

Learn Python in One Day

The ultimate Python guide

Reach your destination step by step — Original photo by Ruffa Jane Reyes on Unsplash

Python has been an important part of Google since the beginning and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we’re looking for more people with skills in this language. — Peter Norvig, Director of Search Quality at Google, Inc.

Why this Python tutorial?

If you search on google, you will find thousands of Python books, tutorials, and video lectures. But why do I make another Python tutorial?

The reason is simple! Most of the existing Python tutorial needs an abundance of time to consume the basics of Python. Many learners lose their appetite to learn Python by going through such content.

I designed this tutorial straightforwardly so that a learner, even who does not have any programming knowledge, can learn it quickly. Yes, one can learn Python in one day!

First, I explained the various aspects of Python. Then, I designed a coding problem to practice for each topic. By practicing those problems, the learner will learn the basics of Python deeply. After learning the basics, one can go to the next level by doing real-life projects. I hope you will enjoy this journey.

Who is this tutorial for?

This tutorial is for :

  1. The learners who do not have any programming language knowledge.
  2. The learners who have programming language knowledge but are new to learning Python.
  3. The learners who have a medium level of knowledge of Python.

What will you learn?

  • What is Python?
  • What are variables? How did they use in Python?
  • How conditional statements (if-else) works?
  • What are the basic data types of Python?
  • What are mathematical operations in Python?
  • How to define functions?
  • How recursive function works?
  • How does the pass statement work?
  • How try-except expression works in Python?
  • How loop work in Python?
  • How do break and continue statements work in Python?
  • How to work with the list?
  • How to work with dictionaries?
  • Creating objects and classes in Python.
  • How does inheritance work in Python?
  • How *args and **kwargs works in Python?
  • How are modules created in python?

What is Python?

Python, developed by Guido van Rossum in the late 1980s, is one of the most popular and widely used high-level programming languages. It offers code readability and simplicity, allowing programmers to develop applications quickly. Simplicity is one of its most appealing features making it an excellent programming language for beginners to learn.

Python is my favorite programming language because of its simplicity, clear syntax, and library support. Another major reason for choosing Python is a large community especially focusing on machine learning is using this wonderful language.

Google, Facebook, NASA, Amazon, YouTube, and Netflix all use Python to develop different apps. You can read my other post about why should we learn Python?

I used a Jupyter notebook for writing and testing the python codes. I will not cover installing the Jupyter notebook here. You can use the Jupyter notebook from Google Colab.

Let’s dive in the basics of Python programming.

Variables

Variables are names or tags that we used to assign a value and manipulate in our programs. A variable name in Python can only contain letters (a — z, A — B), numbers, or underscores (_). However, the first character cannot be a number. For example, we want to store a user’s name and age in variables. Let’s do it in python:

user_name = 'Riyan'
user_age = 20 

We can also define multiple variables at one go such as:

user_name, user_age = 'Riyan', 20

We can see the value of variables simply using theprint()function.

print(user_name)
print(user_age)

Swap the value within two variables

For example, we have two variables v1 and v2. We Assign the values of v1 and v2 are 30 and 50.

v1 = 'user_information'
v2 = 50
print(v1)
print(v2)

We want to swap the values of v1 and v2 such as v2 would be ‘user_information’ and v1 would be 50. How can we do that in python?

If we swap the value as below, we will get 50 for both variables v1 and v2.

v1 = v2
v2 = v1
print(v1)
print(v2)

Let’s see how can we exchange the value using another variable, in our case, t1.

v1 = 'user_information'
v2 = 50
print(v1) # user_information
print(v2) # 50
t1 = v1
v1 = v2
v2 = t1
print(v1) # 50
print(v2) # user_information

Let’s solve a coding problem.

Problem: Declare two variables userName and userAge and assign Riya and 30 to the variables respectively.

Solution: We already know how to declare a variable and assign a value. Let’s solve the problem as below:

userName = "Riya"
userAge = 30

We can define multiple variables in a single line such as:

userName, userAge = "Riya", 30

Control Flow: conditional statements (If … Else)

It is used to evaluate a certain condition is True or False. If the condition is True, then it executes the command inside the “if” statement.

For example, we want to compare a and b. We declare two variables a and b. Then we assign the values for a and b. In this case, a is less than b. So this program will print out: a is less than b.

a = 5
b = 10
if a < b:
    print('a is less than b')

On the other hand, if the condition is False, then it executes the command inside the “else” statement.

In this case, a is greater than b. The program will first check the if condition. Here, the if condition is False. So the program will execute the else statement. Hence, the following program will print out: a is larger than b.

a = 50
b = 10
if a < b:
    print('a is less than b')
else :
    print('a is larger than b') #a is larger than b

If we would like to check multiple conditions, we can use “elif statement. For example,

Here, we check three conditions. The program first checks the condition inside the if statement. In this case, the condition of the if statement is False. So it will execute the next elif statement. The condition of elif statement is True. So the program will print out: a is equal to b.

a = 10
b = 10
if a < b:
    print('a is less than b')
elif a == b:
    print('a is equal to b')
else :
    print('a is larger than b') #a is equal to b

Python supports the usual logical conditions from mathematics.

  1. Less than: a < b
  2. Greater than: a > b
  3. Equals: a == b
  4. Not Equals: a != b
  5. Less than or equal to: a <= b
  6. Greater than or equal to: a >= b

Let’s solve a coding problem using if-else conditional flow.

Problem: Build an if statement that asks for the user’s name via the input() function. If the name is “Riya” make it print “Please show your passport.” Otherwise, make it print “Thank you NAME”. (Replace Name with user’s name)

Solution: In Python, input()is a built-in function to take the input from a user. We use the input() function to take the user input. When the user type “Riya”, then if the condition will be True and it will print out: Please show your passport. If the user types any other names, else the condition would be True and it will print out: Thank you ‘typed name’.

name = input("Please enter your name: ")
if name == "Riya":
    print("Please show your passport")
else:
    print("Thank you " + name)

Data Types

The data type is a crucial concept in programming. Let’s see the basic data type of Python.

  • Integers

Integers are numbers that do not have a decimal part. For example, -20, -3, 0, 5, 80 etc.

user_id = 33
  • Float

Float are numbers that have decimal parts. For example, -0.253, 5.025, 23.52 etc.

user_profit = 33.58
  • String

String refers to text.

user_name = 'Novac'
  • Formatting Strings using the % Operator
user_name = 'Novac'
user_age = 25
user_profit = 33.58
print("My name is %s. My age is %d and I made profit %g." %(user_name, user_age, user_profit)) 

Let’s solve a string-related problem.

Problem: Concatenate the string ‘Learn’, ‘Python’, ‘in’, ‘One’, ‘Day’ to a single string, ‘Learn Python in One Day’.

Solution: We can concatenate the string using the + operation. We also add “ ” for the space among words.

con_string = "Learn" + " " + "Python" + " " + "in" + " " + "One" + " " + "Day"
print(con_string)

Basic Operators and Symbols

We can perform various mathematical operations. For example, we have two variables x_variable and y_variable and we will perform the basic operations on Python.

  • Addition (+)
x_value = 5
y_value = 3
z_value = x_value + y_value
print(z_value) # 8
  • Subtraction (-)
x_value = 5
y_value = 3
z_value = x_value - y_value
print(z_value) # 2
  • Multiplication (*)
x_value = 5
y_value = 3
z_value = x_value * y_value
print(z_value) # 15
  • Division (/)
x_value = 5
y_value = 3
z_value = x_value / y_value
print(z_value) # 1.6666666666666667
  • Floor division (//)
x_value = 5
y_value = 3
z_value = x_value // y_value
print(z_value) # 1
  • Modulus (%)
x_value = 5
y_value = 3
z_value = x_value % y_value
print(z_value) # 2
  • Exponent (**)
x_value = 5
y_value = 3
z_value = x_value ** y_value
print(z_value) # 125
  • Assignment operators (=)

In Python, = is used as an assignment operator. Here, x_value is a variable, and the = symbol indicates that it assigns the value of 50.

x_value = 5
  • Assignment sign with the addition operator, (+=)
x_value = 5
x_value += 2 # x_value = x_value + 2
print(x_value) #7
  • Assignment sign with the subtraction operator (-=)
x_value = 5
x_value -= 2 # x_value = x_value - 2
print(x_value) #3
  • Assignment sign with the multiplication operator(*=)
x_value = 5
x_value *= 2 # x_value = x_value * 2
print(x_value) #10

Let’s solve a mathematical operational problem in Python.

Problem: Calculate the value of y (y = x³ — 2x² + 5x + 10) when the value of x is 3.

Solution:

x = 3
y = x**3 - 2*(x**2) + 5*x + 10
print(y)

Looping / Iterator

  • For Loop

We use for loop to execute a block of code repeatedly until the condition in the for statement is True.

For example, we have a list named student_name and we want to print each element of the list. Let’s see how can we do it.

student_name = ['Lisa', 'Moon', 'Trout']
print(student_name[0]) # Lisa
print(student_name[1]) # Moon
print(student_name[2]) # Trout

If the list is so large, it’s very time-consuming to print this way. However, we can use for loop to do the same task easily.

student_name = ['Lisa', 'Moon', 'Trout']
for e in student_name:
    print(e) 

Let’s see another example. We have a list of numbers from 1 to 6. We want to add all the numbers.

a = list(range(1, 10))
print(a) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
total = 0
for e in a:
    total += e
print(total) # 45

Let’s move on to another example. We want to add only the even numbers from the list.

a = list(range(1, 10))
print(a) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
total = 0
for e in a:
    if e % 2 == 0:
        total += e
print(total) # 20
  • While Loop

We also use a while loop to execute a block of code repeatedly until the condition in the while loop is True. We have already seen how to use for loop. The same task we will perform using a while loop.

total = 0
j = 1
while j < 10:
    total +=j
    j +=1
print(total) #45
  • Nested Loops

A nested loop is a loop inside a loop. The “inner loop” will be executed one time for each iteration of the “outer loop”:

name = [ "Mahfuj", "Arish", "Amena" ]
countries = [ "Bangladesh", "Australia", "USA", "Sweden" ]
for n in name:
    for c in countries:
        print(n + " visited " + c)

Let’s see another example:

for n in range (1, 101):
    c = 0
    for i in range(2, (n//2 + 1)):
        if(n % i == 0):
            c = c + 1
            break
if (c == 0 and n!= 1):
        print( n, end = '  ')

Nested loop using while loop.

i = 2
while(i < 100):
   j = 2
   while(j <= (i/j)):
       if not(i%j): break
       j = j + 1
   if (j > i/j) : 
       print (i, end = '  ')
   i = i + 1
  • Break

We can stop the loop using break statement.

student_name = ['Lisa', 'Moon', 'Trout']
for e in student_name:
    if e == 'Moon':
        break
    print(e)
  • Continue

We can use the continue statement to stop the current iteration of the loop and start the next:

student_name = ['Lisa', 'Moon', 'Trout']
for e in student_name:
    if e == 'Moon':
        continue
    print(e)

Problem: Write a program that will find all such numbers which are divisible by 7 but are not a multiple of 5, between 2000 and 3200 (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.

Solution: print(“\b”) produces a backspace character so that the last comma will be deleted.

for e in range(2000, 3201):
    if e % 7 == 0 and e % 5 != 0:
        print(e, end=",")
print("\b") 

Try, Except

When an error occurs in one block of code, python will normally stop and generate an error message. For some reason, if we want to continue to run the code even if there are some errors, how can we do that? Try and except statements are capable to handle this type of situation. Let’s seen an example. This code will raise an error as x is not defined.

print(x)

If we want to continue to run the code, we can use try and except in this situation.

try:
    print(x)
except:
    print('How are you')

Functions

We can define a function as a collection of instructions or code. A function is defined using the def keyword:

def function1():
    print('This is my first function.')
    print('The job of this function is to print two sentences.')

To call a function, use the function name followed by parenthesis:

function1()

In the example, we have seen that a function is a collection of instructions.

We can also pass data into a function. A function can return data (mapping) as a result. data can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. We can add as many arguments/inputs as you want, just separate them with a comma.

def function2(x, y):
    return x + y

We can call this function passing two arguments as,

a = function2(5, 6)
print (a) # 11

Let’s have another example of creating a function where a function can work as a mapper and collector of instructions.

def function3(x):
    print(x)
    print('This is an another example of creating function')
    return x*2

Let’s call this function.

b = function3(4)
print (b) 

Let’s create a BMI calculator.

def bmi_calculator(name, weight, height):
    bmi = weight / (height ** 2)
    print ("bmi: ")
    print (bmi)
    if bmi < 25:
        return name + " not overweight"
    else: 
        return name + " is overweight"

Calling this function.

name = str(input("Enter Name : "))
height = float(input("Enter Your Height in m : "))
weight = float(input("Enter Your Weight in Kg : "))
result = bmi_calculator(name, height, weight)
print (result)
  • Recursive function

A function can call other previously defined functions. It is also possible to call itself and this is called a recursive function. Let’s see an example of a recursive function. For example, we want to define a function and the job of this function is to find the factorial of an input number.

def factorial(a):
    if a == 1:
        return 1
    elif a < 0:
        print("Sorry, the factorial of negative numbers are not defined")
    else:
        return (a * factorial(a-1))print("Please type a number")
input_number = int(input())
print("The factorial of", input_number, "is", factorial(input_number))

Here, factorial()is a recursive function as it calls itself (return (a * factorial(a-1))).

  • Pass Statement

Function definitions cannot be empty; however, if we have an empty function definition for any reason, we have to add the pass statement to prevent an error.

def function1():
  pass

Problem: Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case, just return 20.

sorta_sum(3, 4) → 7 sorta_sum(9, 4) → 20 sorta_sum(10, 11) → 21

Solution:

def sorta_sum(a, b):
    if (a + b) >= 10 and (a + b) <= 19:
        return 20
    else:
        return a + b

List

A list is a collection of multiple items in a single variable. To define a list, we use square brackets:

a = [1, 5, -3, 'Ary']
print (a) #[1, 5, -3, 'Ary']

We can add items to the list using the predefined function append.

a.append(50)
print(a) #[1, 5, -3, 'Ary', 50]

We can delete items in the list using the predefined function pop.

a.pop()
print(a) #[1, 5, -3, 'Ary']

We can also retrieve the specific item from the list using the concept of the index. The index starts with 0 in python like in other programming languages.

print(a[0]) # 1
print(a[1]) # 5
print(a[2]) # -3
print(a[3]) # Ary

We can also iterate through the list using an index number.

b = [20, 30, 50, 70]
for i in range(len(b)):
    print(b[i])

Dictionary

Dictionary is a collection of key:value pairs to store data. Dictionaries are written with curly brackets, and have keys and values:

c = { 
    'name': 'Ary',
    'ID': 500,
    'country': 'Bangladesh'
    }

Here name, ID and country are the keys whereas Ary, 500 and Bangladesh are the values.

We can access the value of a dictionary using the key.

print(c['name']) # Ary
print(c['ID']) # 500

We can add key:value in an existing dictionary.

c ['new_key'] = 100
print(c['new_key']) # 100

We can also delete a key:value pair from a dictionary using the key.

c.pop("country")
print(c) # {'name': 'Ary', 'ID': 500, 'new_key': 100}

We can also iterate through the dictionaries to get the values of a dictionary.

c = { 
    'name': 'Ary',
    'ID': 500,
    'country': 'Bangladesh'
    }
for x in c:
    print(c[x])

Here we can iterate through a dictionary to get the key:value pairs.

c = { 
    'name': 'Ary',
    'ID': 500,
    'country': 'Bangladesh'
    }
for k, v in c.items():
    print("key: ")
    print(k)
    print("value:")
    print(v)
    print(" ")

Classes and Objects

Python is an object-oriented programming language. Object-oriented programming is a form of programming structure that involves grouping related properties (attributes/instance variables) and behaviors (methods) into individual objects.

An object is a collection of properties that can be expressed as attributes and functions. A Class is a model or a blueprint for creating objects.

Creating a class:

class Person:
    def __init__(self, name, country, age):
        self.name = name
        self.country = country
        self.age = age
        
    def introduce_self(self):
        print("My name is " + self.name)
        print("I live in " + self.country)
    def tell_age(self):
        print("My age is %d" %self.age)

Creating objects using the class:

p1 = Person("Ary", "Australia", 30)
p2 = Person("Sam", "Bangladesh", 40)
p1.introduce_self() 
p2.introduce_self() 
p1.tell_age() 
p2.tell_age()

Problem: Define a class that has at least two methods:

getString: to get a string from console input

printString: to print the string in the upper case. Also please include a simple test function to test the class methods.

Solution:

# define a class 
class IOS:
  def __init__(self):
    pass
  def getString(self):
    self.inp = input()
  def printString(self):
    print(self.inp.upper()) 

Now, we will create an object using the IOS class and will see how can we call a method of a class.

# create a object using class IOS
a  = IOS()
#call the getString method
a.getString()
#call the printString method
a.printString()

Inheritance in Python

In practice, a class consists of complex tasks or methods, and creating a class is time-consuming. In python, we can borrow methods from one class to another class. This is called inheritance.

Python inheritance allows us to create a class that borrows all the methods and properties from another class. To understand the concept of inheritance, we need to understand the following two terms:

A child class, also known as a derived class, is a class that inherits or borrows from another class.

A parent class, often known as a base class, is the one from which the child class is derived.

In Python, using the inheritance:

  • We can borrow the methods and attributes from the parent class.
  • We can change the methods and attributes of the child class that we don’t need.
  • We can add new methods and attributes to our child class.

Advantages of using inheritance in Python:

  • We don’t have to put as much effort into our new class because we’re employing a pre-used class.
  • As we borrow methods(functions) and attributes of a parent class, we need less amount of time to create a new class as a result code repetition has been reduced.
  • We can write more reusable code using inheritance.
  • Inheritance allows us to write more organized and structured code.

Let’s see an example.

We will create a parent class first and then we will create a child class where we will inherit the attributes and methods of the parent class.

Creating Parent class

Any class can be a parent class and the syntax of the parent class is exactly a normal class that we discussed earlier.

Here, we create a class named Person as below:

class Person:
  def __init__(self, firstName, lastName, homeCountry):
     self.firstName = firstName
     self.lastName = lastName
     self.homeCountry = homeCountry
  def printName(self):
     print(self.firstName, self.lastName)
  def printCountry(self):
     print(self.homeCountry)

Now, we will create an object using the Person class.

a = Person("Shuma", "Jan", "Australia")
a.printName()
a.printCountry()

Creating Child class (without adding attributes and methods)

Let’s create a child class where we will inherit the attributes and methods from the parent class. This time we will not add any methods and attributes.

class Student(Person):
  pass

We use the pass statement when we do not want to add any attributes and methods of the child class.

Now, we will create an object using the Student class.

b = Student("Alex", "Ken", "USA")
b.printName()
b.printCountry()

Here, we used the attributes and methods from the Person class.

Creating Child class (adding attributes and methods)

We use __init__()function to add attributes and methods of a child class. The child class will no longer inherit the parent’s __init__() function when we add the __init__() function in the child class.

If we want to keep the inheritance of the parent’s __init__() function, we have to add a call to parent’s __init__() function.

Let’s see the following example:

class Student(Person):
    def __init__(self, firstName, lastName, homeCountry, universityName):
        Person.__init__(self, firstName, lastName, homeCountry)
        self.universityName = universityName
    
    def printUniversity(self):
        print(self.universityName)

Here we want to use the parent class’s __init__() function, that’s why we used the parent’s init function (Person.__init__).

Now, we will create an object using the Student class.

c = Student("Shuma", "Jan", "Australia", 'QUT')
c.printName()
c.printCountry()
c.printUnioversity()

Using super() function

We can also use super() function to add a call to parent’s __init__() function.

class Student(Person):
  def __init__(self, firstName, lastName, homeCountry, universityName):
      super(Student, self).__init__(firstName, lastName, homeCountry)
      self.universityName = universityName
  def printUnioversity(self):
      print(self.universityName)

We can also write down the child class using super () function in the following way:

class Student(Person):
  def __init__(self, firstName, lastName, homeCountry, universityName):
      super().__init__(firstName, lastName, homeCountry)
      self.universityName = universityName
  def printUnioversity(self):
      print(self.universityName)

Creating objects using the child class:

d = Student("Shara", "Alex", "Australia", 'QUT')
d.printName()
d.printCountry()
d.printUnioversity()

*args and **kwargs

We already know about passing the arguments to a function. Let’s see an example first.

We define a function to add three numbers.

def addition(a, b, c):
    return a + b + c
result = addition(4, 5, 6)
print(result)

a, b, c are the arguments of our defined addition function. It is noted that this addition function takes 3 arguments.

Now, if we want to add to numbers, how can we use this function.

result_new = addition(3, 10)
print(result_new)

We will get the following error as the addition function takes 3 inputs, but we pass two arguments when we called the function.

TypeError: addition() missing 1 required positional argument: 'c'

We have to modify the function again.

def addition(a, b):
    return a + b 
result = addition(3, 13)
print(result)

It’s always haste to modify function frequently when the number of arguments is varied.

*args and **kwargs are used to tackle this problem.

We can pass a variable number of arguments to a function using two special symbols.

*args is known as non-keyword arguments and **kwargs is called keyword arguments.

Let’s see an example where we will solve the aforementioned problem.

def addition(*args):
    sum = 0
    for e in args:
        sum += e
    return sum
print(addition(3, 8))
print(addition(41, 10, 16))
print(addition(1, 2, 3, 4, 5))

We can now pass any number of variables to the function.

We use **kwargs to pass a variable length of keyword arguments as a dictionary.

The name is args and kwargs are by convention. We can use any other meaningful names.

Let’s see an example of using **kwargs.

def total_students(**kwargs):
    sum = 0
    for e in kwargs.values():
        sum += e
    return sum
  
print(total_students(Science=5, Arts=7, Business=8))
print(total_students(Science=15, Arts=10))

Modules

A module is a file that contains Python statements and definitions. We utilize modules to split large programs into smaller which are more manageable, and well-organized. Modules also allow for code re-usability.

We usually define our most used functions in a module and import it instead of copying the functions into different programs.

To create a module in python, we save the required code in a file with the file extension.py . Let’s see an example. We want to create a module named example.py .

def add(x, y):
    z = x + y
    return z
def sub(x, y):
    z = x - y
    return z

We write down the following code on a file and named the file as example.py.

import example
a = example.add(8, 5)
print(a)
b = example.sub(8, 5)
print(b)

We can also import the module in a smaller form which is also known as creating an alias of a module.

import example as e
a = e.add(8, 5)
print(a)
b = e.sub(8, 5)
print(b)

That’s all. I hope this tutorial would help you to learn Python programming. I would like to conclude with a popular saying by Bruce Lee, “Practice makes perfect. After a long time of practicing, our work will become natural, skillful, swift, and steady.” It's very true to learn about a new programming language. If you practice regularly, you will improve your coding skills after certain a time, and you will be able to develop wonderful applications.

If you want to learn more advanced topics on Python, feel free to write in the comment section or send me a private note. I will include those topics either in this tutorial or a new one.

A GOOD NEWS!

I will post Python challenges with solutions. It would be great if you solve those challenges with your own method/approach first, and then you could cross-check the solutions. If you like to get my future post, please follow me. Please find the Python challenges in my other posts and have fun!

Before you leave:

If you enjoy reading Medium stories, you can support me and thousands of other writers by becoming a member on Medium using my referral link. It only costs $5 per month and gives you unlimited access to all stories. If you sign up with this link, I will receive a small commission but it won’t cost you any extra. I would be really grateful. You can also support me by throwing some money into my tip jar on Ko-fi or Paypal. To contact me: [email protected]

Programming
Machine Learning
Technology
Science
Artificial Intelligence
Recommended from ReadMedium