Skip to main content

Learning Python Basics

                           Python Basics

Python Basics




What is VARIABLES in Python?

As the name implies the meaning, a variable is something which can be change. A variable is a way of referring to a memory location used by a computer program. A variable is a symbolic name for this physical location.

This memory location contains values, like numbers,text or more complicated types.
Variables can be treated as a container which can store some value in it.

In any other languages for example C++, This is how you write a variable int a = 20
Where int is data type of the variable. Int stands for integer.
String refers to text or collection of characters. It is represented in single quotes or double quotes.
Float refers to decimal point numbers.
In Programming languages like C++ you have to specify the data type of a variable. But in python you don’t have to worry about data type. Whatever value  you give the variable, python will automatically find out the data type. Thus making it much easier to write code in python.
Some variable declaration and their data types.
a = 200 – integer variable
a = “Aidox” – string variable
a = 5.8 – floating point variable

What are INPUT FUNCTIONS in Python?

To print text onto the screen in python all you have to do is:      print(“Your Text”)

To print value of a variable: print                  (variable_name)

But printing values is not enough to make programs.

Sometimes your program will need to receive values from user.

That is where input functions come in Input function

Syntax for simple porgram:

variable_name = input()
If variable is a string.
variable_name = int(input())
If variable is an integer.
Also a text can be printed along so that user have a
better idea on what task they have to perform.
variable_name = input(“Enter the word”)
variable_name = int(input(“Enter the number”))

Comments

Popular posts from this blog

Features of python

  Python   is a dynamic, high-level, free open source, and interpreted programming language. It supports object-oriented programming as well as procedural-oriented programming. In Python, we don’t need to declare the type of variable because it is a dynamically typed language. For example, x = 10 Here, x can be anything such as String, int, etc. Features in Python There are many features in Python, some of which are discussed below – 1. Easy to code: Python is a high-level programming language. Python is very easy to learn language as compared to other languages like C, C#, Javascript, Java, etc. It is very easy to code in the python language and anybody can learn python basics in a few hours or days. It is also a developer-friendly language. 2. Free and Open Source: Python language is freely available on the official website and you can download it from the given download link below click on the  Download Python  keyword. Download Python Since it is open-source, thi...

Using input command in python

Today i will show you that how can you use input command in python language, so we will write a simple program that will ask for any name or value and then print that name or value. So here is our simple program. a= input ( "Enter your name" ) print (a) as you can see we have declared "a" a variable that will ask for input "Enter your name" and then print command will print the variable "a". So anything we will type will be printed. As show in the picture below. But here you have to remember, if you are working with integers for some mathematical work than you have to declare input type as integer because then python will take input type as integer and not as word. As show in the picture below. As you can see the syntax that how can we declaring the input type,,int, we have to write int then in brackets we have to enter the input command, int stands for integer and it will declare our input as integer, we have and in print command we have instruc...

Functions

FUNCTIONS Functions are the already defined part of the program which can be recalled from other parts of the program as many times as needed. Functions plays an important role in helping to reduce the program code. Function has basic three parts: 1. Function Definition 2. Function Call 3. THE FUNCTION DEFINITION The FUNCTION DEFINATION: The function definition deals with purpose/task of the function. It tells the python what the function does. Syntax: Def function_name(arguments): Function body. Example: Def Add(a,b): Print(a+b) Arguments are the variables used in function. You cannot skip variable name in function definition. THE FUNCTION CALL Function call passes the variable values to function definition, the number of values must match the number of parameters. Syntax: Function_name(values) Example: Add (5,6) Gives output 11 RETURN STATEMENT : Return statement can be used to return function result to function call: Def add(a,b): Return (a+b) Now return sends the value of sum back ...