Welcome

sampleqa.in tutorials, Python Programming  tutorial,Python Classes

Python Classes


Class: A class is a blueprint, an idea of something, It doesnt exists as a usable function, rather it describes how to make something. This blueprint can be used to create object(s).

    There are two types of classes,

  • Builtin Classes
  • User-Defined Classes

Built-in Classes are declared and defined in Python Framework

for example: built-in class str ,it has all methods related to string handling. Programmers no need to look at different clases for string handling functions, all related methods are packed together,to form a single unit called string class.

Similiary int,float,list,tuple,set and dictionary all are built-in classes.

Finding the Type of the Class
>>> type(1)

<class 'int'>
>>> type(1.1)
<class 'float'>
>>> type([1])
<class 'list'>
>>> type((1))
<class 'int'>
>>> type((1,))
<class 'tuple'>
>>> type({1,})
<class 'set'>
>>> type({1:1,})
<class 'dict'>

User-Defined Classes are declared and defined by the Programmer

User defined class Syntax:
class  class_name(object):
	statements
	....
	statements

	method1
	medthod2
	........
	methodN

ADS