Page 132 - 2622_Delhi Police Public School_C-8
P. 132

Interdisciplinary Learning                                                   Lab Activity


                  Create a Python program to find the HCF and LCM of two numbers using function.



              STRING

              A sequence of characters which is enclosed or surrounded by single (‘ ’), double (“ ”), or tipple (“‘ ’”)
              quotes is known  as a string. The sequence may include  a letter,  number, special characters  or a
              backslash. Python treats single quotes as double quotes.
              Example of a string:

              str = 'This is Shweta\'s pen.'
              print (str)
              Output:
              This is Shweta's pen.


              Creating a Single-line String

              Single-line  Strings  can  be  created by  enclosing  characters inside  single  or double  quotes.  It  is  like
              assigning a value to a variable.

              Program 3: To create a single-line string

                   Program3.py                                                 Output
                File  Edit  Format   Run   Options   Window    Help         Aadya
                                                                            Kaushal
                first_name = 'Aadya'
                print (first_name)
                last_name = 'Kaushal'
                print (last_name)
                str = ' '
                print (str)



              Multiline String


              A multiline string in Python begins and ends with either three single quotes or three double quotes. Any
              quotes, tabs, or newlines in between the “triple quotes” are considered part of the string.
              Program 4: To print multiline string

                   Program4.py

                File  Edit  Format   Run   Options   Window    Help

                print('''A sequence of
                characters are called a string.
                Strings are used by programming
                languages to manipulate text such
                as words and sentences.''')





                        Premium Edition-VIII
                130
   127   128   129   130   131   132   133   134   135   136   137