Page 436 - CITS - Computer Software Application -TT
P. 436

COMPUTER SOFTWARE APPLICATION - CITS




           •  Python3
           for letter in ‘geeksforgeeks’:

               # break the loop as soon it sees ‘e’
               # or ‘s’
               if letter == ‘e’ or letter == ‘s’:

                   break
           print(‘Current Letter :’, letter)
           Output:

           Current Letter : e
           Python Pass
           We use pass statements to write empty loops. Pass is also used for empty control statements, functions, and
           classes.
           •  Python3

           # An empty loop
           for letter in ‘geeksforgeeks’:
               pass

           print(‘Last Letter :’, letter)

           Output:
           Last Letter :

           Python String
           Till now, we have discussed numbers as the standard data-types in Python. In this section of the tutorial, we will
           discuss the most popular data type in Python, i.e., string.
           Python string is the collection of the characters surrounded by single quotes, double quotes, or triple quotes. The
           computer does not understand the characters; internally, it stores manipulated character as the combination of
           the 0’s and 1’s.
           Each character is encoded in the ASCII or Unicode character. So we can say that Python strings are also called
           the collection of Unicode characters.
           In Python, strings can be created by enclosing the character or the sequence of characters in the quotes. Python
           allows us to use single quotes, double quotes, or triple quotes to create the string.
           Consider the following example in Python to create a string.
           Syntax:
           1  str = “Hi Python !”
           Here, if we check the type of the variable str using a Python script

           1  print(type(str)), then it will print a string (str).
           In Python, strings are treated as the sequence  of characters, which  means that Python doesn’t support the
           character data-type; instead, a single character written as ‘p’ is treated as the string of length 1.
           Creating String in Python
           We can create a string by enclosing the characters in single-quotes or double- quotes. Python also provides triple-
           quotes to represent the string, but it is generally used for multiline string or docstrings.





                                                           423

 CITS : IT&ITES - Computer Software Application - Lesson 120 - 137  CITS : IT&ITES - Computer Software Application - Lesson 120 - 137
   431   432   433   434   435   436   437   438   439   440   441