Python for Beginners begunpro

Python Learning Day 3-4

Python

Welcome back to our Python journey on BegunPro! Today, we’re delving into the realms of input/output and string manipulation. These are powerful tools that will add versatility to your Python programming skills. So, let’s dive in with some simple examples!

If you have not read road plan for python journey please read about that first, from this Link.

Input and Output in Python

Input: In Python, you can get input from the user using the input() function. Here’s a quick example:

				
					# Get user input
user_name = input("Enter your name: ")

# Display a greeting
print("Hello Mr, " + user_name + "!")
				
			

In this example, the input() function prompts the user to enter their name, and the print() function displays a greeting using the entered name.

Output: The print() function is your friend for displaying information. You can use it to output text or the values of variables:

				
					age = 25
print("I am", age, "years old.")

# Output text
print("Welcome to BegunPro!")
				
			

String Manipulation

Strings in Python are versatile, and you can manipulate them in various ways.

Concatenation: Combining strings is easy using the + operator:

				
					first_name = "Begun"
last_name = "Pro"
full_name = first_name + " " + last_name
print("Full Name:", full_name)
				
			

String Length: You can find the length of a string using the len() function:

				
					message = "Python is amazing!"
length_of_message = len(message)
print("Length of message:", length_of_message)
				
			

Substring: Extracting a portion of a string is done using indexing:

				
					sentence = "Learning Python is fun!"
substring = sentence[8:14]
print("Substring:", substring)
				
			

Iterate String

To iterate through a string in Python, “for…in” notation is used.

				
					str = "hello"
for c in str:
  print(c)
  
# h
# e
# l
# l
# o

				
			

Built-in Function len()

In Python, the built-in len() function can be used to determine the length of an object. It can be used to compute the length of strings, lists, sets, and other countable objects.

				
					length = len("Hello")
print(length)
# Output: 5

colors = ['red', 'yellow', 'green']
print(len(colors))
# Output: 3
				
			

Practice Examples

  1. String Concatenation
  2. Immutable Strings
  3. IndexError
  4. Python String .format()
  5. String Method .lower()
  6. String Method .strip()
  7. String Method .title()
  8. String Method .split()
  9. Python String Method .find()
  10. String Replace
  11. String Method .upper()
  12. String Method .join()

Great job exploring input/output and string manipulation in Python! These are essential skills that will serve you well as you continue your coding journey.

In the next blog, we’ll tackle conditional statements, so stay tuned. As always, feel free to experiment with the code, ask questions, and most importantly, enjoy the process of learning Python!

Happy coding on BegunPro!

Facebook
Twitter
LinkedIn

1 thought on “Python Learning Day 3-4

Comments are closed.