CHAPTER 2: " PYTHON" ( VARIABLES AND DATA TYPES)
Variables and Datatypes
A variable is the name given to a memory location in a program for example
- a = 34 IN
- b = "He"
- C = 722.56
Data Types
Primarily there are following data types in Python Integers
1. Integers
2. Floating point numbers. Strings
3.Strings
4.Booleans
5. None
Python is a fantastic language that automatically identifies the type of data for us.
a = 71 --( Identifies a as classs<int>)
b = 88.44 => Identifies b as class < flat >
name = "He" →Identifies name as class <Str>
Rules for defining a Variable name → Also applies to other identifiers.
- A variable name can contain alphabet's, digit's and underscores.
- A Variable name can only start with an alphabet and underscore.
- A Variable name cant start with a digit .
- No while space is allowed to be used inside Variable name.
Examples of a few variable names are : her, ones, seven, -Seven etc..
Operators in Python
following are some common operators in Python
1. Arithmetic operators => +, -,*, / ,etc."
2. Assignment operators ⇒ = , + =, - = ,etc.
3. Comparison operates => ==, >,>=, <, !=, etc.
4. Logical operators => and, or, not
type () function and Typecasting :
type function is used to find the data type of a given variable in Python.
- a = 3
- type(a) => class < int>
- b="31" type
- type (b) => class <str>
A number can be converted into a string and Vice versa (If possible) . There are many functions to convert one data type into another.
- str(31)=> "31" Integer to String Conversion
- int("32") => 32 string to Integer conversion
- float (32) = 32.0 Integer to float Conversion
and so on.....
Hear "31 " is a string literal and 31 a numeric literal.
input() function
Mast This function allows the user to take input from the keyboard as a string
a = input (" Enter name")
It is important to note that the output of input is always a String ( even if the number entered )
THANK YOU;
FOLLOW ME ON INSTAGRAM: "teacherseye360"
Comments
Post a Comment