0% found this document useful (0 votes)
29 views4 pages

Day-1-Basics - Ipynb - Colaboratory

The document discusses Python variables and data types. It demonstrates how to store different data types like integers, floats, strings, and booleans in variables. It also shows various arithmetic, comparison, and logical operators that can be used on variables. Functions like type(), int(), float(), str() are used to check and change data types. User input is taken using the input() function and various ways to convert input to required data types are presented.

Uploaded by

Ankur Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

Day-1-Basics - Ipynb - Colaboratory

The document discusses Python variables and data types. It demonstrates how to store different data types like integers, floats, strings, and booleans in variables. It also shows various arithmetic, comparison, and logical operators that can be used on variables. Functions like type(), int(), float(), str() are used to check and change data types. User input is taken using the input() function and various ways to convert input to required data types are presented.

Uploaded by

Ankur Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

4/17/22, 8:30 PM Day-1-Basics.

ipynb - Colaboratory

# Variables  ( placeholders )  we can store values inside a variable
x=10                                    # int       # storing 10 inside x vaiable  # = is ass
y=12.22                                 #    float type vaiables
z='welcome in python lecture'           #    String value
w=True                                  #    boolean  True/False
p='A'                                   #    String

print("value of x is =",x)              # ctrl+enter ( run our program)
print("value of y is =",y)
print("value of z is =",z)
print("value of w is =",w)
print("value of p is =",p)              # print is a predefiend function to display output

value of x is = 10

value of y is = 12.22

value of z is = welcome in python lecture

value of w is = True

value of p is = A

# how to check data type of variables

print("type of x is =", type(x))      # type is a predefined function

print("type of y is =", type(y))

print("type of z is =", type(z))

print("type of w is =", type(w))

print("type of p is =", type(p))

type of x is = <class 'int'>

type of y is = <class 'float'>

type of z is = <class 'str'>

type of w is = <class 'bool'>

type of p is = <class 'str'>

# Arithmetic Operators

x=16

y=3

print("x+y =", x+y)

print("x-y =", x-y)

print("x*y =", x*y)

print("x/y =", x/y)

print("x//y =", x//y)          # this will skip decimal part (keep only int value) [floor div
print("x%y =", x%y)            # this will return remaining part after a division  [remainder
print("x**y =", x**y)          # power

x+y = 19

x-y = 13

x*y = 48

x/y = 5.333333333333333

x//y = 5

x%y = 1

x**y = 4096

https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 1/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory

# comparision operator

x=40

y=20

print("x < y =", x < y , "###x is less than y###")

print("x > y =", x > y)

print("x <= y =", x <= y)

print("x >= y =", x >= y)

print("x == y =", x == y)          # equal to

print("x != y =", x != y)          # not eqaul to     !(not)

x < y = False ###x is less than y###

x > y = True

x <= y = False

x >= y = True

x == y = False

x != y = True

# how change data type of variable

x=12.22

print(type(x)," ====> ",x)

y=int(x)           # converting float value into integer

print(type(y)," ====> ",y)

<class 'float'> ====> 12.22

<class 'int'> ====> 12

x=123

print(type(x)," ====> ",x)

y=str(x)             # converting integer into string

print(type(y)," ====> ",y)    # we can not use this value for the calculation

<class 'int'> ====> 123

<class 'str'> ====> 123

x=True                           

print(type(x)," ====> ",x)

y=int(x)             # converting bool into int  (True is 1)(False is 0)

print(type(y)," ====> ",y)   

<class 'bool'> ====> True

<class 'int'> ====> 1

x="5250"

print(type(x)," ====> ",x)

y=int(x)             # converting String into integer

print(type(y)," ====> ",y)    # we can use this value for the calculation

<class 'str'> ====> 5250

https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 2/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory

<class 'int'> ====> 5250

x="A"

print(type(x)," ====> ",x)

y=ord(x)             # converting String into integer  [Ascii value]

print(type(y)," ====> ",y)    # we can use this value for the calculation

<class 'str'> ====> A

<class 'int'> ====> 65

x=65

print(type(x)," ====> ",x)

y=chr(x)             # converting int into String  [Ascii value]

print(type(y)," ====> ",y)    # we can use this value for the calculation

<class 'int'> ====> 65

<class 'str'> ====> A

# how to take user input
name= input("please enter your name")
print("welcome"," ",name)

please enter your namesanjeev sir


welcome sanjeev sir

x=int(input("please enter x value"))          # input is a predefined function to take user i
y=int(input("please enter y value"))
z=x+y             # logic (calculation)
print("output z =",z)

please enter x value22

please enter y value22

output z = 44

# find out area of triangle
# area = 1/2*(l*b)
l=float(input("please enter l value"))  # input always receive value in string
b=float(input("please enter b value"))  # convering value as per our requirement
area=(l*b)/2
print("area is =", area)

please enter l value3.56

please enter b value4.2

area is = 7.476000000000001

https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 3/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory

check 7s completed at 8:27 PM

https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 4/4

You might also like