DEV Community

MAHDIN
MAHDIN

Posted on

PYTHON FOR BEGINNERS Part 1

WHAT IS PYTHON?

In today’s data age, python has become one of the major leading languages to work with. It is not only used to connect to various database systems but also for making accessing, working and modifying them easy. Python is an object-oriented, high-level programming language with integrated dynamic semantics primarily for web and app development.

WHY PYTHON IS USEFUL?

  1. Easy to learn and use

  2. English like commands

  3. No need to write everything from scratch.

  4. Lengthy problems solved in few lines with the help of libraries

INTRODUCTION TO PYTHON

VARIABLE AND DATA TYPES

VARIABLE: Variable is a reserved memory location where we can store the values.

Suppose you are John. You want to print your name as an output. So, first you have to declare a variable. Put your name on the variable then print your name.

Image description

Here name is a variable and "John" is the value.

DATA TYPES:

We use variables to store values and every value in python has a data type.

Integer: 4,6,8,9.
Float: 2.3,5.7,9.8.
Complex Number: 5+3i,7+2i,10+3i (Here i is imaginary number)
String: "John","Adam"
List: ['red','blue','green']
Tuple: ('red','blue','green')
Boolean: True or False
Dictionary: {"name":"John","age":"22",}

type() function

There is a function named type which we mostly use to find a type of a variable.

Image description

Arithmetic Operation

1.Addition (+)

Image description
2.Subtraction (-)

Image description
3.Multiplication (*)

Image description
4.Division (/) (output of a division will always be a float)

Image description
5.Floor Division (//)

Image description
6.Modulus (%)

Image description
7.Exponentation (**)

Image description

Assignment Operators

If we want to add or multiply a number from a variable(a) and store the value on the variable we added or multiplied from (a=a+7 or a=a*7), then we have to use these assignment operators:

  1. Add and assign (+=)

Image description

  1. Subtract and assign (-=)

Image description

  1. Multiply and assign (*=)

Image description

  1. Divide and assign (/=)

Image description

  1. Modulus and assign (%=)

Image description

  1. Exponent and assign (**=)

Image description

  1. Floor Division and assign (//=)

Image description

input () function

If we want to take input from user, we usually use input () function.

Image description
Basically, input function always returns a string.
[]

So, if we want a numeric value as an output, we have to convert the string with int,float or any kind of built in functions.

Image description

Top comments (0)