1

Python 101: Getting Started With Modern Python

 2 years ago
source link: https://dev.to/felixia/python-101-getting-started-with-modern-python-1f50
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Cover image for Python 101: Getting Started With Modern Python
Felix Olonde

Posted on Feb 14

Python 101: Getting Started With Modern Python

Python is one of the top most sorted out programming language with a vast usage from web development to data science and Machine Learning. Being a scripting language, python is not only easy to learn but also easy to write as it has English-like syntax.

Python has various data types which includes numerical values, string, data structure which includes list, tuple, set and dictionary.
Declaring a variable in python is as easy as below:
name = Wambua
You can define several variables in a raw as below:
a, b, c = 1, 2,3
To display an output in python, you use the function print
For example

name = 'Otieno'
age = 12
print(name)

Enter fullscreen mode

Exit fullscreen mode

Integers and floats are numerical data type in python. If you want know the type of data you are dealing with you use the function type(). For example:

age = 33
type(age) #int

Enter fullscreen mode

Exit fullscreen mode

String is another data type in python. Unlike other languages, python does not have a character. It therefore treats a character as a string of length 1.
To know the length of a string, python uses the function len()

name = 'Daniel'
result = len(name)
print(result) #6

Enter fullscreen mode

Exit fullscreen mode

Functions are blocks of code that do a specific job. In python, functions are defined as below:

def add_2(x):
return x+2

Enter fullscreen mode

Exit fullscreen mode

To call a function, you just have write the name of the function followed by parenthesis then passing the argument if any.

add_2(5)

Enter fullscreen mode

Exit fullscreen mode

Data structures in python are containers for storing data for processing. These includes

-List
-Dictionary
-Tuples
-Set
We shall discuss in details the functionalities of the above data structures. Keep learning!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK