GVK CHINMAYA VIDYALAYA SENIOR SECONDARY SCHOOL Kothuru, Indukurupet, SPS Nellore Data Handling Class: 11 Subject: Python Teacher: C Vijaya
In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories: Python Data Types Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview
In Python, the data type is set when you assign a value to a variable:
Python Numbers There are three numeric types in Python: ● int ● float ● complex Variables of numeric types are created when you assign a value to them:
Output
String Literals String literals in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function: Eg: a=”hello” print(a) Eg: a=”””Welcome to gvkcv At Indhukeurpet””” print(a)
Strings are Arrays Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.
Slicing You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string.
String Length To get the length of a string, use the len() function.
Boolean Values In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer:
Dictionary A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values. Python Dictionaries
Output
Core Data Types
Every variable in python holds an instance of an object. There are two types of objects in python i.e. Mutable and Immutable objects. Whenever an object is instantiated, it is assigned a unique object id. The type of the object is defined at the runtime and it can’t be changed afterwards. However, it’s state can be changed if it is a mutable object. To summarise the difference, mutable objects can change their state or contents and immutable objects can’t change their state or content. ● Immutable Objects : These are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object can’t be changed after it is created. Mutable vs Immutable Objects in Python
Mutable Objects : These are of type list, dict, set . Custom classes are generally mutable.
Every Python object has three key attributes associated to it 1. The type of an object 2. The value of an object 3. The id of an object
1. The type of an object The type of an object determines the operations that can be performed on the object. Built-in function type() returns the type of an object.
2. The value of an object The value is the literal itself and for a variable the data iis the data-item(the variable) it is currently referencing. Print statement can display the value of an object.
3 .The id of an object Id of an object is the memory location of the object.
Truth Value Testing Value with truth value as false Values with truth value as truth None All the other values are considered true False (Boolean value False) Zero for any numeric type,for example 0,0.0,0j Any empty sequence eg:( ),[ ], Any empty mapping eg: { } www.gvkcv.in
The or operator combines two expressions,which make it operands.The or operator works in these ways: ● Relational expressions as operands ● Numbers or strings or lists as operands The or operator
Relational expressions as operands: The or operator evaluates to true if either of its (relational) operands evaluates to True;False if both operands evaluate to False. Eg: (4==4) or (5==8) results into True because first expression is True 5>8 or 5<2 results into False because both expressions are False
Numbers / Strings / list as operands: In an expression x or y , if first operand has False then return second operand y as result. Eg: 0 or 0 0 First expression is false so second expression is returned 0 or 8 8 First expression is false so second expression is returned 8 or 0 8 First expression is true hence first expression is returned “Gvkcv” or “ ” “Gvkcv” First expression is true hence first expression is returned “ “ or “gvkcv” “gvkcv” First expression is false hence second expression is returned “ “ or “ “ “ “ First expression is false hence second expression is returned “Python” or “gvkcv” “Python” First expression is true hence first expression is returned
The and operator: ● Relational expressions as operands ● Numbers or strings or lists as operands
Relational expressions as operands: The and operator evaluates to True if both of its operands evaluate to True ; False if either or both operands evaluate to False. Eg: (7==7) and (5==7) results False (2>5) and (5<2) results False 5>2 and 2<5 results True
Numbers or Strings or Lists as operands: In an expression x and y , if first operand has false then return first operand otherwise return second operand. Eg: 0 and 0 0 First expression is false so second expression is returned 0 and 8 0 First expression is false so second expression is returned 8 and 0 0 First expression is true hence first expression is returned “Gvkcv” and “ ” “” First expression is true hence first expression is returned “ “ and “gvkcv” “” First expression is false hence second expression is returned “ “ and “ “ “ “ First expression is false hence second expression is returned “Python” and “gvkcv” “gvkcv” First expression is true hence first expression is returned
The not operator: The logical not operator negates or reverse the truth value of the expression. Eg: not 5 results into true not 0 results into true not -4 results into false
Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11

Data handling CBSE PYTHON CLASS 11

  • 1.
    GVK CHINMAYA VIDYALAYA SENIORSECONDARY SCHOOL Kothuru, Indukurupet, SPS Nellore Data Handling Class: 11 Subject: Python Teacher: C Vijaya
  • 2.
    In programming, datatype is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories: Python Data Types Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview
  • 3.
    In Python, thedata type is set when you assign a value to a variable:
  • 4.
    Python Numbers There arethree numeric types in Python: ● int ● float ● complex Variables of numeric types are created when you assign a value to them:
  • 5.
  • 6.
    String Literals String literalsin python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function: Eg: a=”hello” print(a) Eg: a=”””Welcome to gvkcv At Indhukeurpet””” print(a)
  • 7.
    Strings are Arrays Likemany other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.
  • 9.
    Slicing You can returna range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string.
  • 11.
    String Length To getthe length of a string, use the len() function.
  • 12.
    Boolean Values In programmingyou often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer:
  • 15.
    Dictionary A dictionary isa collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values. Python Dictionaries
  • 16.
  • 17.
  • 18.
    Every variable inpython holds an instance of an object. There are two types of objects in python i.e. Mutable and Immutable objects. Whenever an object is instantiated, it is assigned a unique object id. The type of the object is defined at the runtime and it can’t be changed afterwards. However, it’s state can be changed if it is a mutable object. To summarise the difference, mutable objects can change their state or contents and immutable objects can’t change their state or content. ● Immutable Objects : These are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object can’t be changed after it is created. Mutable vs Immutable Objects in Python
  • 21.
    Mutable Objects :These are of type list, dict, set . Custom classes are generally mutable.
  • 22.
    Every Python objecthas three key attributes associated to it 1. The type of an object 2. The value of an object 3. The id of an object
  • 23.
    1. The typeof an object The type of an object determines the operations that can be performed on the object. Built-in function type() returns the type of an object.
  • 24.
    2. The valueof an object The value is the literal itself and for a variable the data iis the data-item(the variable) it is currently referencing. Print statement can display the value of an object.
  • 25.
    3 .The idof an object Id of an object is the memory location of the object.
  • 31.
    Truth Value Testing Valuewith truth value as false Values with truth value as truth None All the other values are considered true False (Boolean value False) Zero for any numeric type,for example 0,0.0,0j Any empty sequence eg:( ),[ ], Any empty mapping eg: { } www.gvkcv.in
  • 32.
    The or operatorcombines two expressions,which make it operands.The or operator works in these ways: ● Relational expressions as operands ● Numbers or strings or lists as operands The or operator
  • 33.
    Relational expressions asoperands: The or operator evaluates to true if either of its (relational) operands evaluates to True;False if both operands evaluate to False. Eg: (4==4) or (5==8) results into True because first expression is True 5>8 or 5<2 results into False because both expressions are False
  • 34.
    Numbers / Strings/ list as operands: In an expression x or y , if first operand has False then return second operand y as result. Eg: 0 or 0 0 First expression is false so second expression is returned 0 or 8 8 First expression is false so second expression is returned 8 or 0 8 First expression is true hence first expression is returned “Gvkcv” or “ ” “Gvkcv” First expression is true hence first expression is returned “ “ or “gvkcv” “gvkcv” First expression is false hence second expression is returned “ “ or “ “ “ “ First expression is false hence second expression is returned “Python” or “gvkcv” “Python” First expression is true hence first expression is returned
  • 35.
    The and operator: ●Relational expressions as operands ● Numbers or strings or lists as operands
  • 36.
    Relational expressions asoperands: The and operator evaluates to True if both of its operands evaluate to True ; False if either or both operands evaluate to False. Eg: (7==7) and (5==7) results False (2>5) and (5<2) results False 5>2 and 2<5 results True
  • 37.
    Numbers or Stringsor Lists as operands: In an expression x and y , if first operand has false then return first operand otherwise return second operand. Eg: 0 and 0 0 First expression is false so second expression is returned 0 and 8 0 First expression is false so second expression is returned 8 and 0 0 First expression is true hence first expression is returned “Gvkcv” and “ ” “” First expression is true hence first expression is returned “ “ and “gvkcv” “” First expression is false hence second expression is returned “ “ and “ “ “ “ First expression is false hence second expression is returned “Python” and “gvkcv” “gvkcv” First expression is true hence first expression is returned
  • 38.
    The not operator: Thelogical not operator negates or reverse the truth value of the expression. Eg: not 5 results into true not 0 results into true not -4 results into false