Python Basics (Learn python right away now) - Programmer's Academy

Python Basics (Learn python right away now)

Python is considered as a base or startup language for new programmers because of its simplicity, ease to write English sentence like syntax. Syntax is basically structure and set of rules for programming language such as we have English, Hindi, or Urdu. Each programming language has a different syntax. In this article we will go through some basics of python and we will write our first code

Print Function(Output)

So, we will start with the first code to print hello python on the screen. To tell computer In python to write some text to the screen we have to use keyword print like this

Print(“Hello Python”)

Print() is a built-in function in Python to display things on screen. Built-in function is predefined in the language and can be used directly. Now let us run this on the IDE or CMD whatever your preference is. Remember whatever you want to display remains in quotes “ “.

Congratulations we have written our first python program. Give it a try yourself!

Comments

Now the next thing is comments. Comments are basically written so that the function performed could be understood easily. For example, you multiplied two numbers in your code, so you write that here I multiplied some numbers for some other function I want to perform   to remind yourself when you open your code again. Comments are optional but an important part and good programming practice. How to write comments in python? Well let us see here.

Any sentence followed by a “ # ” is comment. Comments do not affect program flow as they are ignored by compiler.

Data types

Data type is attribute of data that defines which type of value(s) data possess or what is the type of data on which we will perform functions. Is it a number, sentence or characters?

Python has various data types like other languages. That provide support to different types to data. Most used data types are

    1. Floating number
    2. Character
    3. String
    4. Long INT
    5. Boolean (True or False)
    6. Integer (int)

Variables

Next thing is variables. In programming variables are used to store some values such as a bottle is used to store water, or a box is used to store something just like that. These values can be either numbers, alphabets, sentence, characters etc. Python is smart enough to understand what type your variable does store when it is declared despite other languages in which you must mention for example in C++to store integer in variable you have to mention int. To store a value in variable in python we use

Variable name = value to be stored

Let us do this. Here a is variable name and 60 is value stored in it.

Another example

NOTE: to store string we must write inside double quotes such as “c” variable value as in the example

User input

Let us consider you are writing a program to multiply two numbers; how will you know those two numbers? Either you will assign two numbers yourself or you will ask user of your program to assign two number to get data from user . So how you can do that? Let us understand this with an example.

Note: Remember while programming you must keep in mind that you are developing the program for user so think from user perspective

In this example we asked user to input First number and second number for which he want multiplication. Then simply multiplied two variables in which user input was taken by using Input() function as explained earlier

Remember while using the variables we must define their type such as we defined integer type in above example. It is python language rule to define the type while using variables unlike other languages which require to define type while declaration of variable

Help Me Please: If you found any error in the content or example please let us know by comment also write your suggestion or if any doubt in the concept please feel free to write us in the comment section.

Practice your Code online here

(Visited 199 times, 1 visits today)

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
You cannot copy content of this page
Scroll Up
0
Would love your thoughts, please comment.x
()
x

  • Name

  • Minimum length of 8 characters.