DEV Community

Evans Van
Evans Van

Posted on

Python 101: Ultimate Python Guide or Introduction to Modern Python

Introduction

Python is a high level programming language that was developed by Guido van Rossum.
Python is meant to be an easily readable language. Its formatting is visually uncluttered, and it often uses English keywords where other languages use punctuation. Unlike many other languages, it does not use curly brackets to delimit blocks, and semicolons after statements are allowed but are rarely, if ever, used.
It is also referred to as general purpose programming language due to its wide range of applications such as:

Data Analytics

Web Development

Machine Learning & AI

Wed Data Scraping

Data Science

Desktop Applications

Data Types

There are several data types in Python. The main data types that you’ll probably see the most are string, integer, float, list, dict and tuple.

  1. String Strings are usually created in one of three ways. You can use single, double or triple quotes. Let’s take a look!.
>>> my_string = "Welcome to Python!"
>>> another_string = 'The bright red fox jumped the fence.'
>>> a_long_string = '''This is a
multi-line string. It covers more than
one line'''
Enter fullscreen mode Exit fullscreen mode

They can be manipulated in different ways through Concatenation, Replication, Slicing and other String Methods.


a = 'Hello'
b = 'World'
#string Concatenation
a + b # returns HelloWorld
#string Replication
a * 3 # returns HelloHelloHello

len(a) # length of string -- in this case 5
b[0] #returns first letter - W
b[-1]#returns the last letter - d

a.upper()    #converts to uppercase HELLO
a.lower()    #converts to uppercase hello
b.title()    #converts to titlecase World
Enter fullscreen mode Exit fullscreen mode

2.List
A Python list is similar to an array in other languages. In Python, an empty list can be created in the following ways.

>>> my_list = []
>>> my_list = list()
Enter fullscreen mode Exit fullscreen mode

A list contains a list of elements, such as strings, integers, objects or a mixture of types. Let’s take a look at some examples:

>>> my_list = [1, 2, 3]
>>> my_list2 = ["a", "b", "c"]
>>> my_list3 = ["a", 1, "Python", 5]
Enter fullscreen mode Exit fullscreen mode

3.Tuples
A tuple is similar to a list, but you create them with parentheses instead of square brackets. You can also use the tuple built-in. The main difference is that a tuple is immutable while the list is mutable. Let’s take a look at a few examples:

>>> my_tuple = (1, 2, 3, 4, 5)
>>> my_tuple[0:3]
(1, 2, 3)
>>> another_tuple = tuple()
>>> abc = tuple([1, 2, 3])
Enter fullscreen mode Exit fullscreen mode

4.Numeric
These values can wither be integers, floats or complex numbers.

5.Boolean
These is either True or False. It can be used mainly for comparison operations and conditional statements.

6.Dictionary
Dictionaries are used to store data values in key:value pairs. A dictionary is created between two curly braces an integer or string can be the key or the value.

A dictionary is a collection which is ordered*, changeable and do not allow duplicates.

dict = {1:'one', 'two':2}
Enter fullscreen mode Exit fullscreen mode

7.Sets
Sets are unordered data structures that store unique elements.They are defined using {} no duplicates are allowed unlike tuples they are mutable.

Running Python
Python comes with its own code editor: IDLE (Integrated Development and Learning Environment).
It allows the programmer to write Python and debug their code quite easily. The reason it is a “lite” debugger is because it is very basic and it’s missing other features.
It’s a Python shell where you can type short scripts and see their output immediately and even interact with code in real time. There is no compiling of the code as Python is an interpretive language and runs in the Python interpreter.

Conclusion
This has been a beginner guide to python which is a great and easy programming language to learn as your first it is easy to read as it uses English Keywords.Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured,object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.

Latest comments (0)