Introduction to Python Programming Input Output Operators and Strings
The document provides an introduction to Python, highlighting its simplicity, versatility, and high demand in the job market. It covers essential programming concepts such as input/output functions, operators, and string manipulations, along with examples and applications. Additionally, it includes practice exercises to reinforce learning.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views15 pages
Introduction to Python Programming Input Output Operators and Strings
The document provides an introduction to Python, highlighting its simplicity, versatility, and high demand in the job market. It covers essential programming concepts such as input/output functions, operators, and string manipulations, along with examples and applications. Additionally, it includes practice exercises to reinforce learning.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15
Introduction to Python
Programming: Input, Output,
Operators, and Strings What is Python? • High-level programming language created by Guido van Rossum • Known for its simplicity and readability • Widely used in web development, data science, and artificial intelligence • Named after the comedy group Monty Python Why Learn Python? • Easy to learn and understand • Large community support • Extensive library collection • Versatile applications • High demand in job market • Cross-platform compatibility Python Input Function • Input() function reads data from keyboard • Syntax: variable = input("prompt message") Always returns data as string type Example:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
Python Output Functions • print() function displays output • Multiple ways to format output: • Basic print: print("Hello World") • Using f-strings: print(f"Hello {name}") • Using .format(): print("Hello {}".format(name)) • Using % operator: print("Hello %s" % name) Arithmetic Operators • Addition (+): \(a + b\) • Subtraction (-): \(a - b\) • Multiplication (*): \(a * b\) • Division (/): \(a / b\) • Floor Division (//): \(a // b\) • Modulus (%): \(a % b\) • Exponentiation (**): \(a ** b\) Comparison Operators • Equal to (==) • Not equal to (!=) • Greater than (>) • Less than (<) • Greater than or equal to (>=) • Less than or equal to (<=) Logical Operators • and: Returns True if both statements are true • or: Returns True if one of the statements is true • not: Reverses the result, returns False if true Assignment Operators • Simple assignment (=) • Add and assign (+=) • Subtract and assign (-=) • Multiply and assign (*=) Divide and assign (/=) Examples of compound assignments Introduction to Strings • Sequence of characters • Created using single or double quotes Immutable data type Example: text = "Hello, Python!" String Operations • Concatenation using + operator • Repetition using * operator • String indexing [index] • String slicing [start:end:step] • Length using len() function String Methods • upper() and lower() • strip(), lstrip(), rstrip() • replace() • split() and join() • find() and index() String Formatting • Using % operator • str.format() method f-strings (formatted string literals) Example of each formatting method
Best practices for string formatting
Common String Applications • Input validation • Text processing • File operations • Data parsing • User interface development Practice Exercises • Write a program to get user input and display it • Create a calculator using arithmetic operators • Compare two numbers using comparison operators • Perform string manipulations using different methods • Format output using various string formatting techniques