1. Write a program to demonstrate basic data type in python.
Theory: Data type defines the kind and they are int, string, float etc. Since everything is an object in Python programming, data types are actually classes and variables are instances (object) of these classes. We don't need to define data types in python because python is a dynamically typed language, it automatically detects data types. Python enables us to check the type of the variable used in the program.
Python provides us the type() function, which returns the type of the variable passed.
String : A string is defined as a collection of one or more characters.
It is putted in single quotes or double quotes or triple quotes i.e (' ') , (" ") or (' ' ' ' ' ') . for eg: s="GoEduHub.com"
List : It is as same as arrays, it contains heterogeneous data types. eg: a=[1,2,"a"] Tuple : Tuples are created by ( ) . it contains heterogeneous data types . eg: t=(1,2,3)
Dictionary: Dictionary is an unordered collection of data. It has key:value pair which is separated by a colon :, and all keys are separated by a ‘,’. eg : d={'a':1, 'b':2, 'c':3}
Procedure:
1. Open your Start menu and choose Python (command line).
a. You should get a prompt that looks like >>>.
b. At the moment, you're doing everything in interactive mode in the Python interpreter. That's where the >>> comes in. Python shows you >>> when you're supposed to type something.
2. At the prompt, type the code to achieve the expected output.
3. Run the code. 4. Check whether the required output is achieved or not
Program:
x = 20 #int
print(x)
print(type(x))
x = 20.5 #float
print(x)
print(type(x))
x = 1j #complex
print(x)
print(type(x))
20
<class 'int'>
<class 'complex'>
#String x = "GoEduHub.com"
print(x)
print(type(x))
GoEduHub.com
0 Comments