P_06 print() function & String concatenation(using +) in Python | Python Tutorials for Beginners
Summary
TLDRThis video script covers fundamental Python programming concepts, focusing on the print function and string manipulation. It demonstrates using a single print function to display multiple lines and explains string concatenation with the '+' operator. The script also highlights the importance of proper indentation to avoid common Python errors, such as syntax and indentation errors. Viewers are given a practical exercise to apply these concepts and are encouraged to engage in the comments section for further discussion.
Takeaways
- 📝 The script discusses the use of the print function in Python for displaying text on the console.
- 🔑 It explains how to print multiple lines using a single print function with the newline character ' '.
- 🔍 The video covers string concatenation in Python using the plus '+' symbol.
- 👀 It highlights the importance of spacing when concatenating strings to avoid unwanted output.
- 🛠️ The script provides three methods to include a space between concatenated strings: after the first string, before the second string, or using a plus symbol in between.
- ⚠️ It warns about the potential for indentation errors in Python if code is not written at the beginning of a line or if there are misplaced spaces or tabs.
- 💻 The presenter demonstrates creating and running a Python file named 'string manipulation' to show examples of print functions and string concatenation.
- 📚 The video includes a practical exercise for viewers to practice string manipulation and concatenation using print functions.
- 📝 The presenter mentions providing notes of the class in the description box for further reference.
- 🔄 The script emphasizes the difference between syntax errors and indentation errors in Python programming.
- 👋 The presenter signs off with a reminder about the next video's topic, which will cover the input function in Python.
Q & A
What is the primary focus of the video script?
-The primary focus of the video script is on learning Python programming language, specifically discussing the print function, string concatenation, and the concept of indentation errors.
How can multiple lines be printed using a single print function in Python?
-Multiple lines can be printed using a single print function in Python by using the newline character '\n' within the print statement.
What is the issue with using three separate print functions to print multiple lines?
-Using three separate print functions to print multiple lines is not efficient and can be avoided by using the newline character within a single print function.
How can two strings be concatenated in Python?
-Two strings can be concatenated in Python using the plus '+' symbol, for example, 'print("hello" + " " + "jenny")'.
Why is it important to handle spaces when concatenating strings in Python?
-It is important to handle spaces when concatenating strings in Python because failing to do so can result in the output strings being printed without any space between them.
What is an indentation error in Python?
-An indentation error in Python occurs when the code is not properly indented according to the language's syntax rules, such as when a space or tab is misplaced at the beginning of a line.
How can an indentation error be identified in Python?
-An indentation error can be identified in Python by the presence of an error message indicating an unexpected indent, and often there will be a red underline in the code editor at the point of the error.
What is the difference between a syntax error and an indentation error in Python?
-A syntax error in Python occurs when the code does not follow the correct syntax rules, such as missing a closing brace. An indentation error, on the other hand, is specifically related to the improper use of spaces or tabs to denote code blocks.
What is the assignment given at the end of the video script?
-The assignment given at the end of the video script is to print a specific output using string manipulation techniques, with the requirement to use either one or multiple print functions to achieve the desired result.
Where can the notes of the class discussed in the video script be found?
-The notes of the class discussed in the video script can be found in the description box of the video.
Outlines
💻 Python Print Function and String Manipulation
This paragraph introduces the concept of using Python's print function to display text on the console. It explains how to print multiple lines using a single print statement by incorporating newline characters ('n'). The speaker also discusses string concatenation in Python, demonstrating how to combine two strings using the plus symbol and the importance of including spaces for proper output. Additionally, the paragraph touches on common errors such as syntax errors and indentation errors, providing examples of how they occur and how to avoid them. The speaker concludes by showing how to create a new Python file and execute basic print statements.
🔍 Exploring String Concatenation and Indentation Errors
The second paragraph delves deeper into string concatenation, illustrating different methods to add spaces between concatenated strings. It emphasizes the need for careful handling of spaces and tabs to avoid indentation errors, which are distinct from syntax errors. The speaker provides a practical demonstration by running Python code snippets that result in both the desired output and an example of an indentation error. The paragraph concludes with an assignment for the viewer to practice creating a specific output using print and string concatenation functions, and a teaser for the next video's topic on the input function in Python.
Mindmap
Keywords
💡print function
💡string concatenation
💡newline character
💡indentation error
💡syntax error
💡string
💡plus symbol
💡assignment
💡input function
💡programming language
Highlights
Introduction to the print function in Python and its usage.
Demonstration of printing multiple lines using a single print function with newline characters.
Explanation of string concatenation in Python using the plus symbol.
Common mistake of concatenating strings without spaces and how to correct it.
Different methods to add spaces between concatenated strings.
The importance of proper indentation in Python to avoid errors.
Explanation of syntax errors and how they differ from indentation errors.
A practical example of creating a Python file for string manipulation exercises.
Running a Python script to demonstrate printing strings with newlines.
Illustration of concatenating strings with spaces in different ways.
Demonstration of an indentation error caused by improper spacing or tabbing.
How to identify and correct an unexpected indent error in Python.
Assignment given to practice string manipulation and concatenation.
Instructions for the exercise to print a specific output using print functions.
Discussion on using the plus sign for string concatenation and newlines with '\n'.
Encouragement for viewers to attempt the exercise and seek help in the comments if needed.
Preview of the next video's topic: the input function in Python.
Note that class notes will be available in the video description for reference.
Transcripts
so in the series of learning python
programming language in previous video
we have discussed like print function we
have discussed how to print something on
console and one coding exercise related
to that print function
this you have printed i guess you would
have to print this thing right now see
how you have printed these three lines
in one print this line in double quotes
in second print this line in third print
to the stand you have used three print
functions
but rather than using three print
functions we can do this we can get this
output with
only one print function half using
slashing right okay see now
how to use that thing
print hello world three hello world in
different
uh line hello world hello world hello
world okay now have to print using one
function only
here we write just hello world
slash n
hello world
again slash n and again
hello world
and double quote close so what output
you will get
this output you will get the slash n
will add a new line
okay
so you don't need to write 3 print
function now
if i want to concatenate two string like
i want to print this thing
hello and after that my name jenny so
the rather than writing hello jenny i i
can print i can concatenate
two strings basically my motto is to
tell you how to concatenate strings in
python
so one string is
this hello
then you can use plus symbol and then
second string is
jenny
this will print
this output no actually
it will not print this output it will
print this thing hello
jenny with no space no space
this plus will only concatenate these
two strings
no space in between hello and jen
okay if you want to add space
how you can do
just practice this
there can be three ways
either you can put some after hello you
can put a space and then closing braces
or second method is before j you can put
a space
you can add a space and then you can
write jenny
third method is what you can do
the string
plus
you can add a space then plus
and
jenny
so now it will print
hello with space gen hello journey with
space in between right so you have added
the space also the space also would be
considered as a string one string this
is two string three string so we are
basically concatenating these strings
using using plus symbol
very simple
okay
but you have to take care
means using of spaces you know can be
dangerous in python
if suppose you add a space here
first you add a space or a tab and then
you start writing print and hello and
something like this
in that case uh you will get an error
indentation error
okay this is second type of error one
type of error we have discussed syntax
here in a previous video
when you are not following the syntax or
the rules of writing programs then you
then we get syntax error like if you
forget to
put here closing braces this is syntax
error
but that would not be syntax error if
you add a space
before these writing before start
writing the code actually in python that
will give indentation indentation error
okay so now let's practice i'll you know
show you on my laptop how you get that
error and how to you know print these
things at all so let's create a new file
right click on this first project new
then file and i'm going to name this
like string
manipulation
okay dot p
y
fine
so same see
in print
i just wanna print
hello
world
with slash n
and again
hello world
now let's run this
okay if you uh you can run like this
right click on this and run string
manipulation okay hello world hello
world two times you get with slash n it
will create a new line this backslash
and slap this n
fine now i want to add two strings like
hello
then with plus
and
jenny
let's run this
and see here you will get hello jenny
with no space if you want to add space
what you can do you can add a space here
either after hello or
second method is
before this writing j
if i run this then you will get a space
hello jenny or you can do it plus
and
one space
then
plus
gen
ok
now i am adding a space space is an
individual string so hello jen you will
get
like this you can get concatenate
strings
now see if you add a space
before this print
before the sprint or i add a tab i have
not i haven't started writing this code
from the beginning of the line but i
have added a tab and then i have start
writing
now let's run this and see if you are
getting correct output c
it is giving an error indentation error
but type of error is what
not syntax error this time it is
indentation error
so this is also important you have to
you know parallely
analyze this thing like
when you get indentation error or syntax
there are these kind of things so if you
see here anywhere indentation error
you come to know that you have added
any
misplaced maybe indent or a space
here also you can see a red underline is
there before this p
okay so if you hover the cursor over it
it will show unexpected indent
fine
and in line number one here see in line
number 1 before the sprint so we cannot
add we cannot write down a quote
something like this you start be careful
start writing code at the beginning of
this line
okay in python
so now
i guess
it's done for string manipulation that's
all
now i'll give you one assignment
so i hope you got how to get concatenate
these strings and what is that
indentation error now one exercise for
you is you have to print this thing as
it is i want this type of output
okay in the previous video also we have
done a coding exercise same thing okay
you have to use print
or it's not like that you have to use
one print only
it's fine you can use one print function
for this second third fourth you can use
four print function here but i want this
output only
same exact output string manipulation
exercise second line string
concatenation is done with
plus sign
in double quote plus sign for example
print hello plus jenny new lines can be
created with a backslash and n
exact output i want on my screen
okay
so i guess you can do this thing if not
you can just let me know in comment
section maybe you can discuss this but i
guess you have if you have done the
previous exercise coding exercise you
can do this thing it's very easy okay
now from the next video we'll see
input function what is input function in
python so nice in the next video till
then bye bye take care okay one more
thing i'm going to add notes of this
class in the description box of this
video you can go and check out
okay
تصفح المزيد من مقاطع الفيديو ذات الصلة
Writing First Python Program | Printing to Console in Python | Python Tutorials for Beginners #lec4
TypesNTypeConversion
Curso Python #06 - Tipos Primitivos e Saída de Dados
you need to learn Python RIGHT NOW!! // EP 1
Python Syntax - Everything you need to know!
C_64 Strings in C- part 3 | printf and puts function in C
5.0 / 5 (0 votes)