Mastering Python in 10 Minutes

Ryandi Pratama Purba
Geek Culture
Published in
7 min readNov 17, 2021

What is Python?

Python is an interpretive programming language that can be used on various platforms with a design philosophy that focuses on code readability and is one of the popular languages ​​related to Data Science, Machine Learning, and the Internet of Things (IoT). The advantages of Python which are interpretive are also widely used for prototyping, scripting in infrastructure management, to the creation of large-scale websites.

Quora, Pinterest, and Spotify all use Python for their backend web development. So let’s learn a bit about it.

The Basics

1. Variables

Another reason was that we can use coding in Python in multiple ways: data science, web development, and machine learning all shine here. Quora, Pinterest, and Spotify all use Python for their backend web development. So let’s learn a bit about it.
Python variable writing itself also has certain rules, namely:

  • The first character must be a letter or underscore _
  • Subsequent characters can be letters, underscores _ or numbers
  • Characters in variable names are case-sensitive. This means that lowercase and uppercase letters are distinguished. For example, the variables firstName and FirstName are different variables.

In Python, it is really easy to define a variable and set a value to it. You simply write a variable and then fill it with a value by adding an equal sign = followed by the value you want to enter. Let’s do it:

we can also use booleans (True/False), integer, strings, float, and many other data types for its value.

2. Conditional Statements

Decision making (if conditions) is used to anticipate conditions that occur during the course of the program and determine what actions will be taken according to the conditions.

In python, there are several statements/conditions including if, else and elif The if condition is used to execute code if the condition evaluates to True.

If the condition evaluates to False, the if statement/condition will not be executed.

Below is an example of using the if condition in Python:

2 is greater than 1, so the “print” code is executed.

The “else” statement will be executed if the “if” expression is false.

3. Looping / Iterator

In the Python programming language, repetition is divided into 3 parts, namely:

  • While Loop: while the statement is true, the code inside the block will be executed. So, this code will print the number from 1 to 10.

The while loop needs a “loop condition.” If it stays true, it continues iterating. In this example, when num is 11 the loop condition equals False.

  • For Loop: Python’s for loop has the ability to iterate over items of any order, such as a list or a string.

Below is an example of using the For Loop .

  • Nested Loop: The Python programming language allows the use of one loop inside another loop. The following sections show some examples to illustrate the concept.

Below is an example of using Nested Loop

4. List: Collection | Array | Data Structure

How to store multiple data in one variable? The answer is using List. List is a data structure in python that is capable of storing more than one data, such as an array.

  • How to Create Lists in Python

We can create a list like a regular variable, but the value of the variable is filled with square brackets ([]). example :

If the list has more than one content, then we can separate it with a comma. This is just a basic list, then I will explain in more detail about the list in another article.

5. Dictionary: Key-Value Data Structure

Python dictionaries are different from lists or tuples. Because each sequence contains a key and a value. Each key is separated from its value by a colon (:), items are separated by a comma, and all are enclosed in curly braces. An empty dictionary without items is written with just two curly braces, like this: { }.

The dictionary value can be of any type, but the key must be an immutable data type such as a string, number, or tuple.

Access Values In Python Dictionary
To access a Dictionary element, you can use the familiar square brackets along with the key to getting the value. Here is a simple example:

Update Values ​​Dictionary In Python

You can update the Dictionary by adding new entries or key-value pairs, modifying existing entries, or deleting existing entries as shown in the simple example given below.

Remove Python Dictionary Element

You can delete individual Dictionary elements or delete the entire contents of the Dictionary. You can also delete the entire Dictionary in one operation.
To explicitly delete an entire Dictionary, just use the del statement. Here is a simple example :

6. Object & Class Python

Python has been an object-oriented language since the Python language itself was created. Creating and using classes and objects in Python is really easy. This tutorial will help you become an expert in using Python object-oriented programming.

If you have no previous experience with object-oriented programming (OOP), you should study it first so you can understand the basic concepts.

If you already understand the basic concepts of OOP, here is an introduction to Object-Oriented Programming (OOP) to help you.

Terms in OOP

  • Class − A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.
  • Class variable − A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class’s methods. Class variables are not used as frequently as instance variables are.
  • Data member − A class variable or instance variable that holds data associated with a class and its objects.
  • Function overloading − The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
  • Instance variable − A variable that is defined inside a method and belongs only to the current instance of a class.
  • Inheritance − The transfer of the characteristics of a class to other classes that are derived from it.
  • Instance − An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
  • Instantiation − The creation of an instance of a class.
  • Method − A special kind of function that is defined in a class definition.
  • Object − A unique instance of a data structure that’s defined by its class. An object comprises both data members (class variables and instance variables) and methods.
  • Operator overloading − The assignment of more than one function to a particular operator.

Creating Python Classes

The class statement is used to create a new class definition. The class name immediately follows the keyword class followed by a colon as follows.

class ClassName: 'Optional class documentation string' class_suite

Below is an example of how to create a class and use it:

Creating Instance Objects

To instantiate a class, you call the class using the class name and pass any arguments that the init method accepts.

Accessing Attributes

You access object attributes using the dot operator with objects. Class variables will be accessed by using the class name as follows:

For a complete example, please see the code below.

That’s it!

We learned a lot of things about Python basics:

  • How Python variables work
  • How Python conditional statements work
  • How Python looping (while & for) works
  • How to use Lists: Collection | Array
  • Dictionary Key-Value Collection
  • Objects and Classes

--

--

Ryandi Pratama Purba
Geek Culture

I am a Blockchain App Developer, I really like coding and technological developments at this time. and I share what I know here. Happy reading