பைதானில் Data Types
Ravichandran J 🇮🇳🇮🇳🇮🇳🇮🇳
Posted on July 10, 2024
*Data Types:
*
- Numeric int float (decimal numbers) complex numbers
- Text( strings= collection of characters,no.,space,etc.,) denoted within quotes.
Boolean
None
Variables and Constants:
Variable = Containers to hold the values
naming variables ( @,!, etc not to be used)
multiple assignments
Tuple
References
Constants (Statice variable)
Formats of Constants(All Caps)
Solution for Exercises:
Create a variable named name and assign your name to it. Then print the value of the variable.
[24]
0s
name= "Ravi"
print(name)
Ravi
Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.
[25]
0s
Age=62
Age=32
print(Age)
32
Assign the values 5, 10, and 15 to three variables a, b, and c in a single line.Print their values.
[26]
0s
a,b,c=5,10,15
print(a,b,c)
5 10 15
Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.
[28]
0s
x,y=5,10
print(x,y)
x,y,=y,x
print(x,y)
5 10
10 5
[29]
0s
x,y=5,10
print(x,y)
x=x+y
y=x-y
x=x-y
print(x,y)
5 10
10 5
[30]
0s
PI=22/7
print(PI)
3.142857142857143
Constant is a static variable.
[31]
0s
PI=22/7
r=10
Area=PI*r*r
print(Area)
314.2857142857143
Define constants for the length and width of a rectangle.
[33]
0s
LEN=4
BRTH=5
A=LEN*BRTH
print(A)
20
Define a constant for π (pi) and a variable for the radius. Calculate and print the circumference of the circle.
[36]
0s
PI=22/7
r=10
C=PI*r+r
print(C)
41.42857142857143
[37]
0s
PI=22/7
r=10
C=PI*(r+r)
print(C)
62.857142857142854
Posted on July 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024