DATA TYPES IN PYTHON
Python categorizes data types into two categories.
1. Mutable
2. Immutable
Mutable: The data types whose values can be changed (e.g. List & Dictionary)
Immutable: The data types whose values can not be changed(numbers , string and
tuple)
STRING
 Strings are a contiguous set of characters enclosed within quotes.
 (a) concatenation: joins thestrings into a single string.
 (b) repetition: repeats the string
 (c) membership: returns true if the character is member of the string
,otherwise returns false.
INDEXING IN STRINGS
 In a string each character is referenced by an Index number. In Python two types of indices are
are used:
(a) Positive integers are used to index from left to right.
(b) Negative integers are used to index from right to left.
STRING SLICING
 Slicing means to extract a piece/portion of an object from the original
object.
 SYNTAX: str[startIndex:endIndex]
BUILT IN STRING FUNCTIONS
 len() : It returns the number of characters in the string str including blank
spaces.
 Capitalize(): It returns the string with its first
letter in uppercase.
. isalnum(): It returns True if the string contains
only alphabets and digits, otherwise it returns
False.
STRING CONSTANTS
 string.asci_uppercase: displays a string containing all uppercase characters.
 String.asci_lowercase: displays a string containing all lowercase characters.
 string.punctuation: displays a string containing all punctuation characters.
LIST
 A List is a sequence of comma-separated values(items) enclosed in square
brackets.
 The items in a list need not be of the same data type.
 It is a mutable data type.
BASIC LIST OPERATION
 Concatenation
 Repetition
 Membership
LIST SLICING
i. It returns the fourth element in the
List.
ii.It returns the elements starting from index 2 to 4
iii. It updates the element present at
index 1
BUILT-IN LIST FUNCTIONS
LIST METHODS
TUPLE
 A tuple is a sequence of commas-separated values(items) enclosed in round
brackets.
 The items in a tuple need not have the same data type.
 A tuple is a sequence of immutable objects i.e. we can not substitute new
elements in a tuple.
 T1=() : An empty tuple is written as parentheses without a value.
 T2=(23, ) : To write a tuple with a single value, we have to include a comma
after it.

DATA TYPES IN PYTHON.pdf

  • 1.
    DATA TYPES INPYTHON Python categorizes data types into two categories. 1. Mutable 2. Immutable Mutable: The data types whose values can be changed (e.g. List & Dictionary) Immutable: The data types whose values can not be changed(numbers , string and tuple)
  • 2.
    STRING  Strings area contiguous set of characters enclosed within quotes.  (a) concatenation: joins thestrings into a single string.  (b) repetition: repeats the string  (c) membership: returns true if the character is member of the string ,otherwise returns false.
  • 3.
    INDEXING IN STRINGS In a string each character is referenced by an Index number. In Python two types of indices are are used: (a) Positive integers are used to index from left to right. (b) Negative integers are used to index from right to left.
  • 4.
    STRING SLICING  Slicingmeans to extract a piece/portion of an object from the original object.  SYNTAX: str[startIndex:endIndex]
  • 5.
    BUILT IN STRINGFUNCTIONS  len() : It returns the number of characters in the string str including blank spaces.  Capitalize(): It returns the string with its first letter in uppercase. . isalnum(): It returns True if the string contains only alphabets and digits, otherwise it returns False.
  • 6.
    STRING CONSTANTS  string.asci_uppercase:displays a string containing all uppercase characters.  String.asci_lowercase: displays a string containing all lowercase characters.  string.punctuation: displays a string containing all punctuation characters.
  • 7.
    LIST  A Listis a sequence of comma-separated values(items) enclosed in square brackets.  The items in a list need not be of the same data type.  It is a mutable data type.
  • 8.
    BASIC LIST OPERATION Concatenation  Repetition  Membership
  • 9.
    LIST SLICING i. Itreturns the fourth element in the List. ii.It returns the elements starting from index 2 to 4 iii. It updates the element present at index 1
  • 10.
  • 11.
  • 12.
    TUPLE  A tupleis a sequence of commas-separated values(items) enclosed in round brackets.  The items in a tuple need not have the same data type.  A tuple is a sequence of immutable objects i.e. we can not substitute new elements in a tuple.  T1=() : An empty tuple is written as parentheses without a value.  T2=(23, ) : To write a tuple with a single value, we have to include a comma after it.