Ad Code

✨🎆 JOIN MERN, JAVA, PYTHON, AI, DEVOPS, SALESFORCE Courses 🎆✨

Get 100% Placement Oriented Program CLICK to new more info click

Data Type in Python,What is Data Type in Python

Python Data Types

Python Data Types – Complete Explanation

A data type defines the pattern, size, and memory allocation of data stored in variables, constants, and methods. Python handles data types internally, so we do not need to pre-declare the type of a variable.

In Python, a single variable can store different data types at different times:

a = 10
a = "hello"
a = True

🔹 Categories of Python Data Types

  • Primitive (Basic) Data Types
  • Derived (Advanced) Data Types

1️⃣ Primitive Data Types

✔ int

Used to store integer numbers.

a = 10

✔ float

Used to store decimal numbers.

a = 12.34

✔ String

A collection of characters. Python supports multiple string formats:

  • Double quotes: s = "data"
  • Single quotes: s = 'data'
  • Triple double-quotes (multi-line text):
    s = """This is a paragraph..."""
  • Triple single-quotes (often used for multi-line comments):
    ''' comment '''

✔ String Examples

a = "

Welcome

" print(a) b = 'hello python' print(b) c = """ This is a long paragraph that spans multiple lines. Python supports this format easily. """ print(c)

✔ boolean

Represents True or False. Used in conditions and loops.

x = True
y = False

🔍 Interesting Boolean Behavior

In Python:

  • True behaves like 1
  • False behaves like 0
s = True
print(s + 1)   # Output: 2

s1 = False
print(s1 + 1)  # Output: 1

print(s + s1)  # Output: 1

2️⃣ Derived Data Types

✔ List

Ordered, indexed, mutable collection.

✔ Tuple

Ordered, indexed, immutable collection.

✔ Dictionary

Stores data as key-value pairs.

✔ Set

Unordered collection of unique items.

✔ datetime

Used to store date and time values.

✔ Class

User-defined data type.

✔ Complex

Used to store complex numbers.

a = 2 + 3j

🔹 Predefined Functions for Data Types

✔ type()

Displays the datatype of a variable.

a = 10
print(type(a))

a = 20.2
print(type(a))

a = 2+3j
print(type(a))

a = (10,20)
print(type(a))

a = [10,20]
print(type(a))

a = {'a':10, 'b':20}
print(type(a))

a = True
print(type(a))

a = "hello"
print(type(a))

✔ int()

Converts numeric string to integer.

a = "123"
a = int(a)    # 123

✔ float()

Converts integer or numeric string to float.

a = 12
a = float(a)     # 12.0

a = "12.34"
a = float(a)     # 12.34

✔ str()

Converts numbers to string.

a = 12
b = str(a)      # "12"
b = str(12.34)  # "12.34"

✔ ord()

Converts a character to its ASCII value.

ord('A')  # 65
ord('a')  # 97
ord('0')  # 48

A–Z → 65 to 90
a–z → 97 to 122
0–9 → 48 to 57

✔ chr()

Converts ASCII value to character.

a = 90
print(chr(a))   # Z

📚 ASSIGNMENT PROGRAMS

  • 1) WAP to convert temperature from Celsius to Fahrenheit.
  • 2) WAP to perform multiplication of a complex number using complex datatype.
  • 3) WAP to evaluate the middle digit of a three-digit number.
  • a = 132  # middle digit → 3
    a = 456  # middle digit → 5
    a = 546  # middle digit → 4
        
  • 4) WAP to print data inside single and double quotes.
"Welcome in SCS"
'Welcome in Python'
'\n hello \n'

إرسال تعليق

52 تعليقات

  1. Program of multiplication of complex numbers using complex data type-->

    x=complex(3+5j)
    print(x)
    y=complex(2+3j)
    print(y)
    multiply=x*y
    print("multiplication of complex numbers=",multiply)

    ردحذف
  2. Program to convert temperature from Celsius to Fahrenheit-->

    c=float(input("enter the value of c"))
    f=(9*c+160)/5
    print("temprature in fahrenheit=",f)


    ردحذف
  3. Program to evaluate the middle number in three-digit numbers based on order-->

    num=int(input("enter the three digit number"))
    a=num%100
    a=a//10
    print("mid number is=",a)

    ردحذف
  4. wap tempuratre celsius to farahenite
    temp=float(input("enter temp in celsius"))
    tf=((temp*(9/5)+32)
    print(tf)

    ردحذف
  5. wap tempurature farahnite to celsius
    tempf=float(input("enter temp in farhenite")
    tc=((temp-32)*(5/9))
    print(tc)

    ردحذف
  6. wap to perform multipication of complex number using complex data type
    comp1=complex(input("enter 1st complex number"))
    comp2=complex(input("enter 2nd complex number"))
    c=(com1*comp2)
    print(c)

    ردحذف
  7. Lokesh Rathore
    Multiplication of Complex Number using Complex Data Type

    Solution:-
    a=complex(2+5j)
    b=complex(4+8j)
    c=a*b
    print("The Multiplication of Complex Number is :- ", c)

    ردحذف
  8. Lokesh Rathore

    Print data in the single quote and double quote ?
    Solution:-
    print("'Hello Lokesh !!!!'")
    '''To Print the String in single Quote, Write the sentence in Double Quote with Single Quote.'''
    print('"Hello Lokesh !!!!"')
    '''To Print the string in Double Quote , Write the sentence in Single Quote with Double Quote.'''

    ردحذف
  9. deependra singh jadaun3 نوفمبر 2020 في 8:31 م

    c=float(input("enter temperature in centigrade"))
    f=((9/5)*c)+(32)
    print(f)

    ردحذف
  10. wap to multiply complex no.
    a=2+3j
    b=3+5j
    print(a*b)

    ردحذف
  11. program to find mid no.
    number=int(input("enter the three digit number"))
    a=number%100
    a=a//10
    print("middle number is=",a)

    ردحذف
  12. program to print any data in single quote and double quote-:
    d=input("enter any data")
    print("'{}'" .format(d))
    print('"{}"'.format(d))

    ردحذف
  13. # PYTHON (6 To 7 PM BATCH)
    # Multiplication of a complex number using complex data type.

    a = complex(input("Enter the First Complex (a+bj) No. :\t"))
    b = complex(input("Enter the Second Complex (a+bj) No.:\t"))
    print("\nResult =\t",a*b)

    ردحذف
  14. #PYTHON( 6 To 7 PM BATCH)
    #To Find the middle number in three-digit numbers based on order .

    a=int(input("Input First number: "))
    b=int(input("Input Second number: "))
    c=int(input("Input Tird number: "))
    if(b<a and a<c):
    print("Middle Number:\t",a)
    elif(a<b and b<c):
    print("Middle Number:\t",b)
    elif(a<c and c<b):
    print("Middle Number:\t",c)
    pass

    ردحذف
  15. Parag Jaiswal

    #WAP to convert temperature from Celsius to Fahrenheit?

    cel = int(input("Enter temperature = "))

    fah = (cel * 1.8) +32

    print("Temperature in fahrenheit is = ", fah)

    ردحذف
  16. Parag Jaiswal
    #WAP to perform multiplication of a complex number using complex data type?

    a =complex(3+5j)
    b =complex(2+4j)

    print(a*b)

    ردحذف
  17. Parag Jaiswal
    3 WAP to evaluate the middle number in three-digit numbers based on order?

    x = int(input("Enter 3 digit number = "))
    a = x % 100
    b = a // 10
    print("Middle number is = ",b)

    ردحذف
  18. Parag Jaiswal
    #WAP to print data in the single quote and double quote


    print('"Stay home, stay safe"')
    print("'Use hand sanitizer & wear mask '")

    ردحذف
  19. multiplication of a complex number:-
    a=2+5j
    b=4+6j
    print("a=",a)
    print("b=",b)
    c=(a*b)
    print("multiplication of a complex number:",c)

    ردحذف
  20. t_c = int(input("Enter Temperature Which you want to Convert into Fahrenheit = "))

    t_f = ((t_c)*9/5+32)

    print(t_f)

    ردحذف
  21. print("print Message in within single quotes")
    print("'Hello Python'")

    ردحذف
  22. print("Print Message in within Double Quotes")
    print('"Hello Python"')

    ردحذف
  23. Reverse five digit number without using loop?
    num = 45798
    a = num%10 #5
    num = num//10 #1234
    b = num%10 #4
    num= num//10 #123
    c = num%10 #3
    num= num//10 #12
    d = num%10
    num= num//10 #1
    e = num%10
    num1 = a*10000+b*1000+c*100+d*10+e*1
    print(num1)

    ردحذف
  24. #NIKHIL SINGH CHOUHAN
    '''WAP to evaluate the middle number
    in three-digit numbers based on order?'''

    i=int(input("enter number"))
    a=i%100
    b=a//10
    print("middle number is=",b)

    ردحذف
  25. ##Program for celcius to Fahrenheit..#Jeet7

    temperature=float(input("enter the value of c"))
    s=(9*temperature+160)/5
    print("temprature in fahrenheit=",s)

    ردحذف
  26. #convert temperature from Celsius to Fahrenheit?
    celsius = float(input("Enter the temperatire in Cilsius : "))
    fahrenheit = (celsius * 1.8) + 32
    print(" %.2f C = %.2f F " %(celsius,fahrenheit))

    ردحذف
  27. #WAP TO CONVERT TEMP.FROM CELSIUS TO FAHRENHEIT?
    C=99
    F=1.8*C+32
    print(F)

    ردحذف
  28. #Wap to multiplication of complex no using complex data type?
    p,q=2+3j,3+4j
    r=p*q
    print(r)

    ردحذف
  29. #Wap to print data in the single quote & double quote?
    print("display'hello python'on monitor")
    print('display"hello python"on monitor')

    ردحذف
  30. #Surendra Singh Rajput
    c=float(input("enter the value"))
    Value =(9*c+160)/5
    print("temprature =",Value)

    ردحذف
  31. #wap to find mid num in e digit number
    #jeet

    Num= int(input("Enter 3 digit number = "))
    x = Num % 100
    x= x// 10
    print("Middle number is = ",x)

    ردحذف
  32. convert celcius to Fahrenheit

    c=float(input("enter temperature in celcius"))
    f=(c*9/5)+ 32
    print("the temperature in fahrenheit is", f)

    ردحذف
  33. multiplication of complex no.

    a=complex(2+4j)
    b=complex(4+5j)
    c=a*b
    print(c)






    ردحذف
  34. multiplication of a complex no.

    a=complex(2+4j)
    b=complex(4+5j)
    c=a*b
    print(c)

    ردحذف
  35. print("'welcome in python'")

    print('"welcome in SCS"')

    ردحذف
  36. Num= int(input("Enter 3 digit number "))
    a= Num % 100
    a= a// 10
    print("number is = ",a)

    ردحذف
  37. a=complex(input("enter First complex number"))
    b=complex(input("enter Second Complex number"))
    c=a*b
    print (c)

    ردحذف
  38. SONAM SINGH
    WAP to convert the multiplication of complex number
    num1=complex(input("enter the first complex number"))
    num2=complex(input("enter the second complex number"))
    complexformula=num1*num2
    print(complexformula)

    ردحذف
  39. #WAP to perform addition and mutiplication complex number without using complex data type
    r1=34
    r2=25
    i1=12
    i2=15
    r=r1*r2-i1*i2
    i=r1*i2+r2*i1
    print("{0}+{1}i".format(r,i))
    #Addition of complex number
    r=r1+r2
    i=i1+i2
    print("{0}+{1}i".format(r,i))

    ردحذف
  40. #WAP to convert temperature from Celsius to Fahrenheit and vice versa
    print("celsius to fahrenheit")
    celsius=float(input("enter the temperature in celsius"))
    fahrenheit=(celsius*9/5)+32
    print(fahrenheit)

    print("fahrenheit to celsius")
    fahrenheit=float(input("enter the temperature in fahrenheit"))
    celsius=(fahrenheit-32)*5/9
    print(celsius)

    ردحذف
  41. #WAP to perform multiplication of a complex number using complex data type
    x=complex(input("enter first number"))
    y=complex(input("enter second number"))

    multiplication=x*y
    print("the multiplication of complex number is", multiplication)

    ردحذف
  42. #celcius to fahrenhet
    # f=(c*9/5)+(32)

    c=float(input("enter the temp. in c"))
    f=(c*9/5)+(32)
    print("the temp.in fahrenhiet to celcius is",c,f)

    ردحذف






  43. num=int(input("Enter Any Number"))
    a=num%100
    a=a//10
    print("Middle Number is ",a)

    ردحذف
  44. # wap to print data in the single quote and double quote?
    print("'how are you'")
    print('" i am fine"')

    ردحذف
  45. # wap to convert temperature from celsius to fahrenheit?
    c=float(input("enter the value of c="))
    f=(9*c+160)//5
    print("temperature in fahrenheit=s",f)

    ردحذف
  46. a=3+4j
    print(a)
    b=5+6j
    print(b)
    c=a*b
    print("multiplication of complex number =",c)

    ردحذف
  47. # wap to display the middle number is a three - digit number?
    num=int(input("enter three digit number"))
    r1=num%10
    num1=num//10
    r2=num1%10
    print(r2)

    ردحذف
  48. multiplication of a complex number using complex data type?

    x= complex(2,3)
    y=complex(2,3)
    z=x*y
    print("Multiplication of complex No",z)

    ردحذف
  49. Devendra Patil

    x= complex(2,3)
    y=complex(2,3)
    z=x*y
    print(z)

    ردحذف
  50. a="'hello world'"
    print(a)

    b='"hello mangal"'

    output - 'hello world'
    "hello mangal"

    ردحذف
  51. WAP to convert temperature from Celsius to Fahrenheit.
    a=float(input("Enter a value which has to be converted :"))
    f=(a*9/5)+32 #This is the formula used to convert the temperature in celsius
    print("The temperature in Fahrenheit is :",f)

    ردحذف

POST Answer of Questions and ASK to Doubt