Page 119 - Code_GPT_Class_8
P. 119

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 Strings

                 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.''')





                                                                                   Functions and String  in Python  117
   114   115   116   117   118   119   120   121   122   123   124