Variables and Data Types in Python

Publicado em: 13 Junho 2017
no canal de: G C Reddy Software Testing
10,429
47

http://www.gcreddy.com/2017/06/variab...
Python Variables and Data Types, Implicit declaration of Data Types, Implicit declaration of Variables in Python,Assign values to variables, delete variables, Python Standard Data Types like Numbers, Strings, Lists, Tuples, and Dictionaries.
We can find data types and variables in every computer programming language like
C, C++, Java etc...And in every Scripting language like Perl, Python, VBScript etc...

What is Data Type?

A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.

Example:
Alfa bytes, Numbers, Boolean values etc...

What is Variable?

A named memory location to store the temporary data within a program, variable value may vary throughout the program and Variables store in primary memory RAM

Implicit declaration of Data types in Python, means no data type specification before declaring the variable.

Ex:

a=10;

Suppose in Java explicit declaration of data types...

Ex:

int a=10;
or
int a;

Implicit declaration of Variables in Python, means we no need to declare variables, we can use directly.

Ex:

num=100;
---------------------------------------
First Python Program:

We can execute Python programs in different modes of programming,

1. Interactive Mode programming
2. Script Mode Programming

Interactive Mode programming:

Invoking the interpreter without passing a script file as a parameter,

Type Python statements one by one and enter, It will execute command by command or
step by step...

Suppose if you have 4 lines of code in your program then type first step/line and enter next second line...like that only we can execute the program

Script Mode Programming

Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished.

Means, first prepare our Python Program in a text editor (ex: Notepad), then launch the Interpreter, and open the Script file then execute the program. Program will be executed continuously...
-----------------------------------------------
No Explicit declaration of Variables in Python, and No data type specification, we can assign any type of data to variables...based on assignment value python considers its data type.

1. Assign values to variables...

counter=10; # An Integer Assignment
distance=20.45; # A Floating Point
name= "Ramu"; # A String

print (counter);
print (distance);
print (name);
-----------------------------------------------
2. Verify Data Type:

Using type(); command we can check the type of data that a variable hold.

a=1;
type(a);
It returns int...

b=2.2;
type(b);
It returns float...

c="abcd";
It returns str...
-----------------------------------------------
3. Multiple Assignments
Python allows us to assign a single value to several variables simultaneously.

Ex:
a=b=c=1;
print (a, b, c);
-----------------------------------------------
We can also assign multiple values to multiple variables.

a, b, c=1, 2.2, "John";
print (a);
print (b);
print (c);
-----------------------------------------------
4. Delete a Variable

We can also delete a variable using del command...

a=123;
print (a);

del(a);
print(a); # It will show error
-----------------------------------------------
5. Standard Data Types in Python...

Python has five standard data types -

Numbers
String
List
Tuple
Dictionary


Nesta página do site você pode assistir ao vídeo on-line Variables and Data Types in Python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário G C Reddy Software Testing 13 Junho 2017, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 10,429 vezes e gostou 47 espectadores. Boa visualização!