BASIC PYTHON
Tags: beginners, lwm, python, programming
Published: 2022-11-19 16:43:52

## Arithmetic Operations in Python
Python adds, subtracts, multiplies and divides integers just like general mathematics, where the specific signs are known as operators such as " +, -, , / ". 

The new arithmetic operations in python are floor division and modulus.

**Floor Division**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62j7ugcq2yey1xbb6y13.png)


5//2 gives 2 since the floor value of 2.5 is 2.

**MODULUS**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxdr1akfnc5c16byh9ak.png)


The answer to 5%2 is 1 as dividing 5 by 2 gives 1 as the remainder and hence the 8%2 will be 0.

## STRING SLICING


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvte516qjt00qxxaq3iu.png)

The index of lists and strings starts from 0. If we want to get a particular character from a string we can use string slicing as shown above. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o67blfr1v20dk1af2qc8.png)

Slicing can also be used to print the entire string using steps and it can also be used to reverse a string shown below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jg8ijce1hyvtyp3s68ah.png)


## LISTS

**Adding elements to a list**

USING APPEND:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guulr6fkg119izztywdq.png)

USING EXTEND

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdtlwr6896xivw0gxeal.png)

We can change specific elements in list using list indexing.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t65tv8tc8lqhoozfyywg.png)

## DICTIONARIES

Dictionaries behave as key values pairs. They hold values through keys.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eh2c8rbl1wjwoux4j2t6.png)

Dictionaries can hold any data types as items


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nofp1eg99wwlypdgpwr9.png)

## TUPLES


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m16nsd4bzi7ntud3o5qu.png)

Tuples are immutable unlike lists. This is the main difference between the two

## SETS

Sets are a collection of unique elements.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5m18ows6gqofuv6gc6p.png)

## FOR and WHILE Loops in Python

Loops print elements in a sequence. The difference between for and while loop is that if we do not know how many times the loop will run we use for loops and if the number of loops in fixed we can use while loop:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31g7xqx5pw70y96a1r0p.png)

## FUNCTIONS


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tx6vblfhkk1p20o1ixh.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/srfq5rukyk4qmp86ep3n.png)


## Built in MAP Function


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oad7a2veg8vdmoc4wbt3.png)

## LAMBDA EXPRESSION

Helps to get rid of defining the entire function.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gakip0asbyjej28dgptz.png)

## FILTER

Filters out elements from a sequence.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th74mjsqawshumq98ifq.png)

Filters out the odd numbers from seq in the above case.

## Splitting a string into list


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi1v83qq08y8uo3nau07.png)

## IN and BOOLEANs


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oil9r95ivwty870c0vrd.png)

## TUPLE Unpacking


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rhjquo2qzm96asmp19ya.png)