Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 14, 2022 06:13 pm GMT

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 = 12print(name)

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 = 33type(age) #int

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

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

def add_2(x):return x+2

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)

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!!


Original Link: https://dev.to/felixia/python-101-getting-started-with-modern-python-1f50

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To