Basic Python
Tags: python, programming, beginners, tutorial
Published: 2022-10-21 05:36:09

Python is a high-level, interpreted, object-oriented, general purpose programming language. It was created by Guido van Rossum, and released in 1991.Python has a simple syntax similar to the English language. Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.

Python was designed for readability, and has some similarities to the English language with influence from mathematics.

Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.

Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

**Data Types**
Python mainly has 4 data types --

1. Integer -- All the whole number is integer
2. Float -- The numbers with the decimal part is float
3. String -- String is a series of character
4. Boolean -- For this data type we only have two values - True and False.


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

**Variable Assignment**
Variables in programming means a memory location where we can store our data. For python syntax for variable assignment is 
var_name = data. Here var_name will be the label of that memory location and by using that we will be able to retrieve the data from the memory location.

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

**Variable Naming Convention**
There are some rules for naming variable. Some of them are mandatory otherwise it will give error and some of them are for readability. 

- A variable must start with a letter or the underscore (_) character. It cannot start with a number.
- Variable names are case sensitive. Means "age", "Age", "aGe" are not the same variable. 
- If the name has more than one word than to separate those words we have to use underscore, we cannot use space


**Let's print "HELLO WORLD"**
Printing means showing something in the console. For that python has a built-in function print().

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

So print function literally takes anything you want to show in the console and shows it.

It can take variables also which will print the value of the variables.

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

Here we can see if we use comma to print two variables then it prints a space between the variables. We can change that using the "sep" argument of print.

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

Again if you notice, every print function creates a new line. Means after the first print, the next one will be in the new line. We can change that also with "end" argument.

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

**Comments**
Sometimes we have to write some notes on our code, so that we can figure out later for which purpose we wrote this piece of code. There are two types of comment:

1. Single Line Comment
2. Multi-line Comment

For single line comment we just need write "#" before the note.

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

For multi-line comments we use triple quotes (""" """ or ''' '''). But one thing to remember, by convention triple quotes are used as a docstring in python. That is why this is not recommended. So if we have to comment multiple lines, we should comment every line with Single Line Comment. To do so, just select every line and press ctrl + /.


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

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

Feel free to ask anything if you don't understand.