What are the uses of python, why should you choose python?
Python was created by Guido van Rossum in the late 1980s. It was designed to be easy to read and simple to use for automation tasks. In the beginning, Python had clean syntax, dynamic typing, and many useful built-in libraries. Over time, Python has grown from handling simple tasks (algebra, visualizations) to supporting complex and powerful operations (Machine learning, web development, software development etc). Today, it is used in data analysis, web development, software development, machine learning, data visualization, and more. Its easy-to-understand code and wide range of uses have made it popular in the industry.
In this blog series, we will learn how to perform data visualization and analysis using Python.
Variables in Python – Variables are containers for storing data, allowing to refer and manipulate information within the program. They can be thought as data containers with label.
We will begin by introducing you to different kinds of variables in python along with their properties
Types |
Example |
Characteristics |
Uses |
Use Case |
str |
"stranger", 'Python123' |
Sequence of characters in single or double quotes |
Storing and processing textual data |
Used for names, addresses, emails, feedback, chatbot conversations, NLP models |
int |
5, -23, 1000 |
Whole numbers (positive or negative) without decimals |
Counting, indexing, basic arithmetic |
Number of employees, age, year, transaction count |
float |
-0.342, 144.6 |
Decimal (real) numbers |
Used in math, analytics, statistics |
Stock prices, interest rates, Weight |
complex |
3 + 4j, -2 - 5j |
Numbers with real and imaginary parts |
Used in scientific and engineering applications |
Electrical engineering calculations, signal processing |
list |
[1, 2, 3], ["a", "b", "c"] |
Ordered, mutable collection of items |
Used to store multiple values |
List of marks, products, tasks, candidates |
tuple |
(1, 2, 3), ("x", "y") |
Ordered, immutable collection of items |
Fixed data grouping |
Coordinates, fixed menu items |
range |
range(0, 10), range(5) |
Sequence of numbers, often used in loops |
Iteration, indexing |
Generating a list of indexes, pages, IDs |
dict |
{"name": "John", "age": 22} |
Unordered collection of key-value pairs |
Mapping, structured data representation |
Storing user profiles, product catalogs |
set |
{1, 2, 3} |
Unordered, unique items, mutable |
Removing duplicates, set operations |
Unique email domains, distinct tags from articles |
frozenset |
frozenset([1, 2, 3]) |
Immutable version of set |
Same as set, but fixed |
Security keys, read-only tags |
bool |
True, False |
Logical values, either true or false |
Conditional logic |
Check login status, comparison results, eligibility criteria |
bytes |
b'hello', bytes([72, 101, 108]) |
Immutable sequence of bytes |
Binary data handling |
Used in file I/O, images, audio, encryption |
Keywords:
In Python, keywords are reserved words that have special meanings and are used to define the syntax and structure of Python programs. Some of the most important keywords include def, used to define a function, and class, which is used to define a new user-defined object (a class). The keyword if is used for conditional branching, along with elif and else for multiple condition handling. Looping is achieved using for and while, and loops can be controlled with break, continue, and pass. The import keyword is used to bring in external modules, while from allows importing specific components. The return keyword sends back a result from a function. The in keyword checks membership and is used for identity comparisons. None represents a null value, and True and False are Boolean constants. The with keyword simplifies resource management, especially with files. lambda is used to create anonymous functions. Additionally, keywords like global and nonlocal are used to modify variable scopes inside functions. All of these keywords play vital roles in writing clear, readable, and functional Python code.
Arithmetic operators:
In Python, arithmetic operators are used to perform basic mathematical operations between variables or values. The + operator is used for addition, which adds two numbers (x + y). The - operator is for subtraction, which subtracts the second value from the first (x - y). The * operator handles multiplication (x * y), and / is used for division, which gives the result as a float (x / y). To get the remainder after division, we use the % operator, known as the modulus (x % y). The ** operator is used for exponentiation, meaning it raises the first number to the power of the second (x ** y). The // operator performs floor division, which returns the largest whole number less than or equal to the result (x // y). These arithmetic operators are commonly used in formulas, calculations, data analysis, and logic building in Python.
Conditional statements and logical operators:
Logical operators in Python are essential tools for decision-making and controlling the flow of a program. Among the most commonly used are and, or, and not. The and operator is used when both conditions need to be true for the entire expression to be considered true. For example, in if age > 18 and has_id:, the code block will execute only if the person is over 18 and possesses an ID. The or operator is used when at least one of the given conditions is true. So, if is_student or is_employee: will execute if either condition is met. The not operator is used to invert a boolean value; not True becomes False, and vice versa.
Apart from these, Python includes control flow keywords like if, else, elif, for, and while. The if statement allows the program to execute a block of code only if a specified condition is true. If it's not, the else block can run an alternative set of instructions. For checking multiple conditions, elif (short for "else if") is used. The for loop is used for iterating over sequences like lists or strings, whereas while continues execution as long as a given condition remains true.
The in operator checks for membership, whether a value exists within a container like a list, string, or dictionary. For instance, 'a' in 'apple' returns True. Together, these logical operators and control flow constructs allow developers to write flexible, intelligent, and responsive Python code that can adapt to various inputs and conditions. Indentation that is white spacing plays an important factor in conditional statements, it leads to indentation errors if not spaced correctly.
In the next part of this series, we will execute these concepts in the coding snippets to check their practical functioning.