Page 426 - ComputerScience_Class_11
P. 426

A string literal is usually written inside single quotes (' ') or double quotes (" "). Python also supports multi-line strings,
              which allow text to span across multiple lines. A multi-line string is enclosed within triple quotes (''' ''' or """ """).
              For example:
                   Program.py
                File  Edit  Format   Run   Options   Window    Help

                  '''Rahul Sharma
                  Orange Education
                  New Delhi'''


              Program 3: To demonstrate different types of literals in Python.

                   Program 3.py
                File  Edit  Format   Run   Options   Window    Help


                  # Numeric Literals
                  x = 10          # Integer literal
                  y = 3.14        # Float literal
                  z = 5 + 2j      # Complex literal

                  # String Literals
                  name = "Python"     # Double-quoted string
                  msg = 'Hello'       # Single-quoted string

                  # Boolean Literals
                  a = True
                  b = False

                  # Special Literal
                  n = None

                  # Multi-line String Literal
                  school_info = """Rahul Sharma
                  Orange Education
                  New Delhi"""

                  # Displaying all values
                  print("Integer Literal:", x)
                  print("Float Literal:", y)
                  print("Complex Literal:", z)
                  print("String Literal (Double Quotes):", name)
                  print("String Literal (Single Quotes):", msg)
                  print("Boolean Literal a:", a)
                  print("Boolean Literal b:", b)
                  print("Special Literal (None):", n)
                  print("Multi-line String:", school_info)








                  424  Touchpad Computer Science (Ver. 3.0)-XI
   421   422   423   424   425   426   427   428   429   430   431