Python String Functions By - Aamir Abdullah Khan Jason J Samuel Sushanth Manish
Objective of the Seminar:  Python String Basics.  Common String Methods  String Concatenation  Formatting Strings  Escape Characters  Slicing  Conclusion
String and String Basics  Python strings are sequences of characters used to represent and manipulate text or data in Python. They are one of the fundamental data types in the Python programming language. Strings are created by enclosing text within single (''), double ("") or triple (''' or """) quotes. For example:
 Important characteristics and uses of Python strings: 1. Text Handling: Python strings are primarily used for text processing and manipulation. They can represent anything from a single character to entire documents. 2. Immutable: Strings are immutable, meaning once they are created, their contents cannot be changed. Operations on strings create new strings rather than modifying the original. 3. Sequence: Strings are sequences of characters, which means you can access individual characters using indexing and perform various sequence operations (e.g., slicing, concatenation). 4. Data Representation: Strings can be used to represent and work with data other than text, such as binary data, serialized data (e.g., JSON, XML), and more. 5. String Methods: Python provides a rich set of built-in string methods that allow you to perform common string operations, such as converting to uppercase or lowercase, splitting, joining, finding substrings, and replacing.
Common String Methods:  len( ): Returns the length (number of characters) of a string. Output: 13  str.lower( ) , str.upper( ): Convert the string to lowercase or uppercase. Output:
 str.strip( ) , str.lstrip( ) , str.rstrip( ): Remove leading and trailing whitespace. Output:  str.split( ): Split a string into a list of substrings based on a separator. Output:
 str.join( ): Join a list of strings into a single string using a separator. Output:  str.replace( ): Replace a substring with another substring. Output:  str.find( ) , str.index( ): Find the index of a substring. Output:
String Concatenation:  In Python, you can concatenate strings using the ‘ + ‘operator, which allows you to join two or more strings together. Here's how string concatenation works: Output: Another example: Output:
Formatting Strings:  String formatting in Python allows you to create well-structured, dynamic strings by incorporating variables and values within text. There are various methods for string formatting in Python, including f-strings, %-formatting, and the str.format() method. Here are examples of each:  F-strings (Formatted String Literals):  F-strings provide a concise and readable way to format strings by embedding expressions within curly braces { }.  Output:
 %-formatting: The ‘%’ operator allows you to format strings by specifying placeholders using ‘%’ and then providing values in a tuple.  Example:  Output: Here, ‘%s’ is a placeholder for a string, and ‘%d’ is a placeholder for an integer.
 str.format( ) method: The ‘str.format( )’ method allows you to format strings by specifying placeholders using curly braces ‘{ }’ and then providing values within the ‘format( )’ method.  Example:  Output:  These are three common methods for string formatting in Python. F- strings are recommended in Python 3.6 and later due to their simplicity and readability.
Escape Characters:  Escape characters in Python are special characters that are used to represent non-printable and special characters within strings. They are preceded by a backslash ‘’. Here are some common escape characters and their usage in Python strings:  Newline Character (‘n’): Represents a line break or a new line. Output:  Tab Character (‘t’): Represents a tab or an indentation. Output:
 Backslash Character (‘’): Represents a literal backslash. Output:  Single Quote (‘`’) and Double Quote (‘``’) Characters: To include a single or double quote within a string. Output:  Unicode Escape (‘u’ and ‘U’): Represents Unicode characters using their code points. Output:
Slicing:  String slicing in Python is a technique used to extract a portion (substring) of a string. You can slice a string using square brackets with a specified range of indices. Here are some examples of string slicing:  Basic String Slicing:
 Negative Index Slicing: Negative indices can be used to count characters from the end of the string.  Slicing with Stride (Step):You can include a third parameter to specify the step (stride) between characters in the slice.
 Slicing with Length: You can use the length of the string to make your slices.  String slicing is a powerful tool for working with text data in Python. It allows you to extract specific portions of strings for various text processing tasks.
Conclusion:  In conclusion we learnt about basics of string functions in python and learnt various methods and techniques that can be used with strings in python. We've learned to harness the power of built-in string methods, enabling tasks such as splitting, and replacing text etc. with precision. And we have learnt about String formatting, including the elegant f-strings in modern Python, allows us to create dynamic and structured text effortlessly.
Input and Output Functions
Objective:  Importance of Input and Output Functions  Python Output Functions  Python Input Functions  Conclusion
Importance I/O Functions 1. User Interaction: I/O operations allow a program to interact with users. They enable input from users via keyboards, mice, touchscreens, or other devices, and they provide output to users through screens, speakers, or other output devices. This interaction is essential for creating user-friendly applications, from command-line tools to graphical user interfaces. 2. Data Handling: Programs often need to read, process, and manipulate data. I/O operations enable programs to access data from external sources like files, databases, or network connections, and to display results or store data for later use. Effective data handling is a core function of software development. 3. Automation: I/O operations are vital for automation. They allow programs to perform repetitive tasks, read and write data in bulk, and make decisions based on input. Automation can lead to increased efficiency, reduced human error, and the ability to perform tasks at scales that would be impractical manually.
Python Output Functions  In Python, we can simply use the print( ) function to print output. For example,  Here, the print( ) function displays the string enclosed inside the single quotation.  Syntax of print( )  In the above code, the print( ) function is taking a single parameter. However, the actual syntax of the print function accepts 5 parameters Here, object - value(s) to be printed sep (optional) - allows us to separate multiple objects inside print( ) end (optional) - allows us to add add specific values like new line “n”
file (optional) - where the values are printed. It's default value is sys.stdout flush (optional) - Boolean specifying if the output is flushed or buffered. Default: FALSE  Example 1:  Output:  Example 2: Python print() with end Parameter:  Output:
 Example 3: Python print() with sep parameter:  Output:  Example: Print Python Variables and Literals:  Output:
Python Input Functions  While programming, we might want to take the input from the user. In Python, we can use the input( ) function. Syntax of input()  Example: Python User Input:  Output:
Conclusion:  In conclusion, this seminar has equipped us with the essential knowledge and skills for effectively working with input and output functions in Python. We've learned how to gather user input using the ‘ input( ) ’ function and provide clear, informative output with the ‘ print( ) ’ function. These fundamental skills are the backbone of Python programming, enabling us to build user-friendly applications, automate tasks, and process data efficiently.

PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT

  • 1.
    Python String Functions By- Aamir Abdullah Khan Jason J Samuel Sushanth Manish
  • 2.
    Objective of theSeminar:  Python String Basics.  Common String Methods  String Concatenation  Formatting Strings  Escape Characters  Slicing  Conclusion
  • 3.
    String and StringBasics  Python strings are sequences of characters used to represent and manipulate text or data in Python. They are one of the fundamental data types in the Python programming language. Strings are created by enclosing text within single (''), double ("") or triple (''' or """) quotes. For example:
  • 4.
     Important characteristicsand uses of Python strings: 1. Text Handling: Python strings are primarily used for text processing and manipulation. They can represent anything from a single character to entire documents. 2. Immutable: Strings are immutable, meaning once they are created, their contents cannot be changed. Operations on strings create new strings rather than modifying the original. 3. Sequence: Strings are sequences of characters, which means you can access individual characters using indexing and perform various sequence operations (e.g., slicing, concatenation). 4. Data Representation: Strings can be used to represent and work with data other than text, such as binary data, serialized data (e.g., JSON, XML), and more. 5. String Methods: Python provides a rich set of built-in string methods that allow you to perform common string operations, such as converting to uppercase or lowercase, splitting, joining, finding substrings, and replacing.
  • 5.
    Common String Methods: len( ): Returns the length (number of characters) of a string. Output: 13  str.lower( ) , str.upper( ): Convert the string to lowercase or uppercase. Output:
  • 6.
     str.strip( ), str.lstrip( ) , str.rstrip( ): Remove leading and trailing whitespace. Output:  str.split( ): Split a string into a list of substrings based on a separator. Output:
  • 7.
     str.join( ):Join a list of strings into a single string using a separator. Output:  str.replace( ): Replace a substring with another substring. Output:  str.find( ) , str.index( ): Find the index of a substring. Output:
  • 8.
    String Concatenation:  InPython, you can concatenate strings using the ‘ + ‘operator, which allows you to join two or more strings together. Here's how string concatenation works: Output: Another example: Output:
  • 9.
    Formatting Strings:  Stringformatting in Python allows you to create well-structured, dynamic strings by incorporating variables and values within text. There are various methods for string formatting in Python, including f-strings, %-formatting, and the str.format() method. Here are examples of each:  F-strings (Formatted String Literals):  F-strings provide a concise and readable way to format strings by embedding expressions within curly braces { }.  Output:
  • 10.
     %-formatting: The‘%’ operator allows you to format strings by specifying placeholders using ‘%’ and then providing values in a tuple.  Example:  Output: Here, ‘%s’ is a placeholder for a string, and ‘%d’ is a placeholder for an integer.
  • 11.
     str.format( )method: The ‘str.format( )’ method allows you to format strings by specifying placeholders using curly braces ‘{ }’ and then providing values within the ‘format( )’ method.  Example:  Output:  These are three common methods for string formatting in Python. F- strings are recommended in Python 3.6 and later due to their simplicity and readability.
  • 12.
    Escape Characters:  Escapecharacters in Python are special characters that are used to represent non-printable and special characters within strings. They are preceded by a backslash ‘’. Here are some common escape characters and their usage in Python strings:  Newline Character (‘n’): Represents a line break or a new line. Output:  Tab Character (‘t’): Represents a tab or an indentation. Output:
  • 13.
     Backslash Character(‘’): Represents a literal backslash. Output:  Single Quote (‘`’) and Double Quote (‘``’) Characters: To include a single or double quote within a string. Output:  Unicode Escape (‘u’ and ‘U’): Represents Unicode characters using their code points. Output:
  • 14.
    Slicing:  String slicingin Python is a technique used to extract a portion (substring) of a string. You can slice a string using square brackets with a specified range of indices. Here are some examples of string slicing:  Basic String Slicing:
  • 15.
     Negative IndexSlicing: Negative indices can be used to count characters from the end of the string.  Slicing with Stride (Step):You can include a third parameter to specify the step (stride) between characters in the slice.
  • 16.
     Slicing withLength: You can use the length of the string to make your slices.  String slicing is a powerful tool for working with text data in Python. It allows you to extract specific portions of strings for various text processing tasks.
  • 17.
    Conclusion:  In conclusionwe learnt about basics of string functions in python and learnt various methods and techniques that can be used with strings in python. We've learned to harness the power of built-in string methods, enabling tasks such as splitting, and replacing text etc. with precision. And we have learnt about String formatting, including the elegant f-strings in modern Python, allows us to create dynamic and structured text effortlessly.
  • 18.
  • 19.
    Objective:  Importance ofInput and Output Functions  Python Output Functions  Python Input Functions  Conclusion
  • 20.
    Importance I/O Functions 1.User Interaction: I/O operations allow a program to interact with users. They enable input from users via keyboards, mice, touchscreens, or other devices, and they provide output to users through screens, speakers, or other output devices. This interaction is essential for creating user-friendly applications, from command-line tools to graphical user interfaces. 2. Data Handling: Programs often need to read, process, and manipulate data. I/O operations enable programs to access data from external sources like files, databases, or network connections, and to display results or store data for later use. Effective data handling is a core function of software development. 3. Automation: I/O operations are vital for automation. They allow programs to perform repetitive tasks, read and write data in bulk, and make decisions based on input. Automation can lead to increased efficiency, reduced human error, and the ability to perform tasks at scales that would be impractical manually.
  • 21.
    Python Output Functions In Python, we can simply use the print( ) function to print output. For example,  Here, the print( ) function displays the string enclosed inside the single quotation.  Syntax of print( )  In the above code, the print( ) function is taking a single parameter. However, the actual syntax of the print function accepts 5 parameters Here, object - value(s) to be printed sep (optional) - allows us to separate multiple objects inside print( ) end (optional) - allows us to add add specific values like new line “n”
  • 22.
    file (optional) -where the values are printed. It's default value is sys.stdout flush (optional) - Boolean specifying if the output is flushed or buffered. Default: FALSE  Example 1:  Output:  Example 2: Python print() with end Parameter:  Output:
  • 23.
     Example 3:Python print() with sep parameter:  Output:  Example: Print Python Variables and Literals:  Output:
  • 24.
    Python Input Functions While programming, we might want to take the input from the user. In Python, we can use the input( ) function. Syntax of input()  Example: Python User Input:  Output:
  • 25.
    Conclusion:  In conclusion,this seminar has equipped us with the essential knowledge and skills for effectively working with input and output functions in Python. We've learned how to gather user input using the ‘ input( ) ’ function and provide clear, informative output with the ‘ print( ) ’ function. These fundamental skills are the backbone of Python programming, enabling us to build user-friendly applications, automate tasks, and process data efficiently.