Monday, 6 March 2017

Fundamental Datatypes in Python

Fundamental Datatypes in Python:

print:

  • print is a built-in function in builtins module.
  • print function is used to prints the values/messages to a stream or sys.stdout by default.
  • syntax:  print( )

id:

  • id is a built-in function in builtins module.
  • returns the identity/address of an object
  • syntax: id(obj)

type:

  • type is a built-in function in bultins module.
  • returns the class type/type of the class
  • syntax: type(obj)

help:

  • help is a predefined function, it will show the help of another functions,methods and modules.

syntax: 

  • help(function name)
  • help(method name)
  • help(function.method)

example:
             help(print)





Integer datatype:

Example:
x=10
print(x)
print(type(x))
print(id(x))

output:

10
<class 'int'>
1717183472

Note:

  • int is a predefined class in builtins module.
  • help(int)



Float datatype:

Example:
y=3.5
print(y)
print(type(y))
print(id(y))

Output:

3.5
<class 'float'>
9218640

Note:

  • float is a predefined class in builtins module.
  • help(float)


Complex datatype:


  • complex number is a combination of real number and imaginary number, here imaginary number is a optional.
Example:


z=3+4j
print(z)
print(type(z))
print(id(z))

Output:

(3+4j)
<class 'complex'>
55236752

Note:

  • complex is a predefined class in builtins module.
  • help(complex)



bool datatype:

  •  bool returns True/False,it is a case-sensitive
  •  the argument is true return True,otherwise return False
Example1:


a=True
print(a)
print(type(a))
print(id(a))

Output:

True
<class 'bool'>
1716928928

Example2:

b=true
print(b)
print(type(b))
print(id(b))

Output:

Traceback (most recent call last):
  File "E:/python_practice/datatypes_blogger.py", line 22, in <module>
    b=true
NameError: name 'true' is not defined


Note:

  • bool is a predefined class in builtins module.
  • help(bool)


string datatype:

Example1:

c="siva"
print(c)
print(type(c))
print(id(c))

Output:
siva
<class 'str'>
58586760

Example2:

d='krishna'
print(d)
print(type(d))
print(id(d))

Output:

krishna
<class 'str'>
56424184

Example3:

e='''siva krishna'''
print(e)
print(type(e))
print(id(e))

Output:

siva krishna
<class 'str'>
55791216

Example4:

f="""siva krishna"""
print(f)
print(type(f))
print(id(f))

Output:

siva krishna
<class 'str'>
56381040

Note:

  • str is a predefined class in builtins module.
  • help(str)

No comments:

Post a Comment