DEV Community 👩‍💻👨‍💻

Cover image for Basic Python
Tanveer Shahriar Arnob
Tanveer Shahriar Arnob

Posted on • Updated on

Basic Python

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

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

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

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

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

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

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

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

Image description

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

Top comments (0)

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. 👀

Join the Hackathon <-