Writing First Python Program | Printing to Console in Python | Python Tutorials for Beginners #lec4
Summary
TLDRIn this video, we learn how to write our first Python program using the PyCharm IDE. The instructor walks us through printing 'Hello, World!' on the console, explaining the usage of the print function in Python 3.x. The video covers the basics of syntax, including proper use of quotes and parentheses, and demonstrates handling syntax errors. It also highlights the differences between Python 2.x and 3.x regarding the print function. Finally, the video offers practical tips on using PyCharm's features, such as syntax highlighting and error identification, ensuring viewers are comfortable with writing and running simple Python code.
Takeaways
- π» The video is part of a series on learning Python, focusing on setting up the development environment with Python and PyCharm IDE.
- π§ Viewers are assumed to have already installed Python 3.10.6 and PyCharm, which are necessary for writing and running Python programs.
- π The first program in any new programming language is traditionally 'Hello World', and the video demonstrates how to print this to the console in Python.
- π₯οΈ Python is an interpreted language, and the base interpreter has been installed as part of the setup process.
- π The `print` function is used in Python 3.x to display output on the console, unlike Python 2.x where `print` was a statement.
- π No need for header files or a `main` function in Python, unlike some other languages like C or C++.
- π The `print` function in Python requires the message to be enclosed in parentheses, which is a syntax requirement specific to Python 3.x.
- π οΈ The video mentions that missing or incorrect syntax will result in errors, which are highlighted by the IDE to assist developers.
- π¨ The PyCharm IDE offers features like syntax highlighting and auto-completion, which help in writing correct and efficient code.
- π The video also touches on the differences between Python 2.x and Python 3.x, emphasizing that the latter requires parentheses for the `print` function.
- π Errors such as 'SyntaxError: missing parenthesis in call to print' are explained, showing how the IDE helps identify and correct mistakes.
Q & A
What programming language is being discussed in the video?
-The video discusses the Python programming language.
What is the purpose of the video?
-The purpose of the video is to teach viewers how to write their first program in Python, specifically how to print 'Hello World' on the console.
What is the difference between Python 2.x and Python 3.x in terms of the print function?
-In Python 2.x, print was a statement and did not require parentheses. In Python 3.x, print is a function and requires parentheses to work properly.
What is the name of the IDE used in the video for Python programming?
-The IDE used in the video is PyCharm.
What is the version of Python discussed in the video?
-The video discusses Python version 3.10.6.
What is the basic syntax for printing a message in Python 3.x?
-In Python 3.x, the basic syntax for printing a message is 'print("message")', where 'message' is the text you want to print.
What happens if you run a print function with an unterminated string in Python?
-Running a print function with an unterminated string in Python will result in a syntax error, specifically an 'unterminated string literal' error.
What is the significance of the parentheses in the print function in Python 3.x?
-In Python 3.x, the parentheses in the print function are necessary because print is a function call, and the text to be printed must be enclosed within them.
What does the video mention about the support for Python 2.x versions?
-The video mentions that support for Python 2.x versions has ended.
What is the file extension for Python files?
-The file extension for Python files is '.py'.
What is the term used to describe the rules for writing programs in a programming language?
-The term used to describe the rules for writing programs in a programming language is 'syntax'.
Outlines
π» Setting Up Python Environment and Writing 'Hello World'
This paragraph introduces the prerequisites for beginning Python programming, including the installation of Python 3.10.6 and the PyCharm IDE. It emphasizes the importance of having a Python interpreter and an IDE to write programs. The speaker guides viewers on how to write their first Python program, which traditionally prints 'Hello World' to the console. The explanation covers the use of the 'print' function in Python 3.x, contrasting it with Python 2.x where 'print' was a statement rather than a function. The paragraph also touches on the concept of an interpreted language and the simplicity of printing to the console in Python without the need for headers or a main function.
ποΈ Customizing PyCharm IDE and Demonstrating 'Hello World'
The speaker discusses changing the color theme in PyCharm for better visibility and comfort. They guide the user through creating a new Python file with the '.py' extension and writing the 'print' function to display 'Hello World'. The paragraph includes a demonstration of how to use the 'print' function, including the auto-completion feature of the IDE, and running the program to see the output. It also covers common errors such as missing quotes and the importance of syntax in programming. The speaker explains the concept of syntax errors and how to identify and correct them, using the PyCharm IDE's features to highlight and resolve issues.
π Understanding Syntax Errors and Advanced 'Print' Function Usage
This paragraph delves deeper into syntax errors, explaining the rules of programming language syntax and the consequences of not adhering to them. The speaker provides practical examples of syntax errors, such as unterminated string literals, and demonstrates how to resolve them. They also show how to use the 'print' function to print blank lines and explain the difference between Python 2.x and 3.x in terms of the 'print' statement and function. The paragraph concludes with a brief mention of future coding exercises related to the 'print' function, setting the stage for the next video in the series.
Mindmap
Keywords
π‘IDE
π‘Python Interpreter
π‘Print Function
π‘Syntax
π‘String
π‘Hello World
π‘Error Handling
π‘Python 2.x vs. 3.x
π‘Auto-completion
π‘Console
Highlights
Introduction to downloading and installing Python and PyCharm IDE.
Installation of Python interpreter version 3.10.6.
Setting up a Python environment with an IDE and interpreter.
Writing the first Python program to print 'Hello World' on the console.
Explanation of the 'print' function in Python 3.x.
Difference between Python 2.x and 3.x regarding the 'print' statement and function.
Demonstration of how to use the 'print' function without additional headers or a main function.
Running a Python file with a .py extension in PyCharm IDE.
Implications of omitting parentheses in the 'print' function in Python 3.x.
Practical demonstration of running a Python program in PyCharm IDE.
Error handling in PyCharm IDE for missing closing quotes.
Understanding syntax errors and their role in programming language rules.
Auto-completion feature of PyCharm IDE for the 'print' function.
Syntax highlighting in PyCharm IDE to identify errors.
Experimenting with the 'print' function to show the effects of missing parentheses.
Explanation of the invisible new line character produced by the 'print' function.
Customization of PyCharm IDE appearance for user preference.
Creating a new Python file in an existing project within PyCharm IDE.
Discussion of single and double quotes usage in Python strings.
Upcoming coding exercises related to the 'print' function in the next video.
Transcripts
so in the series of learning python
programming language
in the previous video we have discussed
like how to download and install
ide for python pycharm we have installed
and
python interpreter you can see python
3.10.6 we have installed right so now i
guess you're all set with your laptop
you have python you have an id to write
your programs right you have that
interpreter also
okay because python is an interpreted
language so we have already
now downloaded and installed a base
interpreter for our python language
i hope you have done this thing
now in this video we'll see
how to print something on console or you
can say we will write our first program
in python
and what usually we do whenever you
learn a new programming language the
first program you write is you print
that
classical hello world
on output screen on the console the same
thing we will do we'll print hello world
on the screen on the console
right in python
so
to print like in c we use which function
print a function in c plus plus we use c
out to print something on the screen
in python what do we use in python 3.10
through point x
version python 1.x python 2.x python 3.x
but python 2.x version they have ended
the support for python two point x uh
version right two point one two point
two like this
now
three point x we are working on three
point ten basically the recent is three
point ten point six
so in this we have a function named
this is the function print
so this we use to print something on the
console
okay
now don't need to read and don't need to
write any header file or anything or
main function or anything
simply you need to write
what
print whatever you want to print
the string or you can say the string
or whatever message you want to print
that we will put here
within these parentheses
okay
so i want to print hello world so simply
in double quotes i'll write
hello world
that's it no semicolon nothing else
if you will run this on your output
screen you will get this program this
output hello world
if you don't print anything if simply
you write print and you click on run
on that file suppose i have a file the
extension of python file is dot py right
so
we are simply running this thing
empty parenthesis
it's okay it will run
what it will print just a blank line
okay
nothing would be shown just a blank line
cursor would be here nothing would be
shown
if i want if you execute two print
function then one and two two blank line
would be shown something like this
right
so
you can say it will
the sprint function
will produce
an invisible new line
character new line means add a new line
so it will produce an invisible new line
character
because of that new line character we
see
you know
a
new blank line on your screen
right i'll show you practically also
now whatever you want to print you just
write within these
codes
we let hello world simply write hello
world so now let me do some experiment
with this uh
what you have to write down this how you
can write down this thing if you don't
put this closing
codes what type of error you will get
and these things let's just do practical
on this
uh print function and see before going
to practical let me just this this is
what in python the syntax is python in
python 3 3.x in python two point x the
previous uh versions
print was just a statement it was not a
function so what we used to write in
that case print
and
hello world whatever you need to print
you can just
write down in these quotes so print
hello world that's it no parenthesis
so it was considered it was as a
statement in python 2.x but here in
python 3 it is
a function so if you are using python 3
point x version right then if you write
something like this if you don't put
these parentheses you will get
error message syntax error message right
if you are using python 2.x version you
can write down print something like this
so let's just do practical of this thing
so we have opened our pycharm ide and
let me just first
change the color
so you can go to file if you want to
change if you are comfortable with this
color you can go for this but i am not
comfortable so go to setting
and appearance in appearance just theme
and
i want
either this this light
or
window 10 lite this one
so you can go for any one
from here you can set these themes okay
so now let's change this color and
just click ok now i guess you can see it
clearly the code fine
now
we have created our first project in the
previous video and first file first dot
py okay
if you want to create another file what
you have to do in the first project on
first project just click right click new
and file and just name your file
okay
so i'm not going to create
in the first dot py only extension is
dot py
we are printing so
okay
how to print just use the sprint
function print
fine let me just write down again p r i
n t print and see it is showing you
this is the you know beauty of this ide
auto completion and see the print syntax
it is showing here you can write down
this values sap and file flash whatever
these things that also one by one will
be discussing but right now just if i
just click enter
it will give me like these parentheses
automatically so now within these
parentheses
i'm adding
hello
world
okay
now let me just run this for you first
see from here i have to select here main
file is selected so i am going to select
current file
so current file is first dot py
current file means i am working in this
file and let's just or you can click in
this
this is the run button or you can just
right click and
this run first
click on this
okay now here
it is going to run now and now it will
print on your screen hello world first
time you know it is taking some time
because of the indexing and all
so see you can see here hello world
fine if i miss this semi-colon this
sorry this um
double quote closing double quote
as you can see a red red underline
means there is something
wrong there is an error okay so this is
what you can say uh
this id will give you these kind of
things if you use id this is you can see
some features or
some advantages of using id c missing
closing codes
so from here only you will come to know
yeah you have missed quotes
or if you run this
here also you will get c now type of
error c syntax error syntax error it is
a syntax error
so types of errors there are many types
of error
okay that also ah with these parallely
with the code we will be seeing
this is what syntax error syntax means
what there are some rules to write
programs in any you know programming
language and those rules are known as
syntax if you don't follow the syntax
then
it will give syntax error
so now syntax or you can say like we
have grammar rules
okay
same in programming language also we
have some rules to write down these
programs so these are syntax known as
syntax
if now it is syntax error because syntax
is what in print
whatever string the message which is not
a code actually
see print is a code it will do something
it will tell the interpreter to do
something but this hello world is
rather than hello world i can write
jenny's lectures i can write
anything else like you are the best
so this is just a message it's not a
code
so other than the code whatever you
write the message or the string that we
will put in
quotes
okay single quotes as well as double
quotes that also will discuss when to
put single code when to put double quote
okay now right now i'm putting double
quote because actually i am from c and c
plus background so
to write down string i used to put the
string the sequence of character as a
string in double quotes
okay
so now see syntax error it will give
syntax error unterminated string literal
hello world this is a string literal it
is unterminated you haven't terminated
this thing detected at line number one
line number one
this is also a skill to identify what is
the error type of error in which line at
all
okay
so you have to you know learn this thing
also parallel
okay now see you can see one arrow here
you have
started this string literal but you
haven't terminated here in line number
one
or if you are not getting what is the
error just simply
the error then text error this thing
copy this thing
open your google
paste that
and just click enter
okay or more specifically you can write
this error in python in whatever
programming language you are
you know practicing you're learning
so generally first you know that link
would be from stack overflow so there
someone has already asked this type of
questions and you will get many answers
simple okay so now let's just first what
you have to do
close this now see after closing
this is what
syntax highlighting also you need to
know the sprint is what in black the
string is what in
green
this hello world plus these codes in
green color okay and if you miss this
and these
ah what you can say
so the sprint is what in not in black
it's in blue and these parentheses are
in black so if you remove this double
quote from here this parenthesis and the
ending of the parentheses parenthesis
this is also in green color so there is
something wrong you can identify
okay
okay now put this one and just
run this again so it will print now
hello world whatever you want to print
you can print now if you don't put this
parenthesis
will give an error see you can see the
red underline here again
okay let me just run this
and it will give again some error see it
is giving syntax error missing
parenthesis in call to print
did you mean this print you are calling
print calling means print is a function
so we are calling print but missing
parenthesis missing parenthesis
because we are using three point
exposures and so
here you have to put
these parentheses
okay
now
okay what you need to do blank print you
can call
see
blank print also you can call it will
not print nothing but a blank line it
will call an individual new line
character so again if i write print
and call
you will see two blank new line same
three four five print plan you will call
these blank line would be increased like
this i hope now print is clear to you
now in next video i'll
discuss a coding exercise with you guys
okay
so i hope every point about print
function is clear to you guys how to
write down your first program how to
print something on console in python now
in the next video we will see a coding
exercise related to this print function
right so i'll see you in the next video
till then bye take
Browse More Related Video
5.0 / 5 (0 votes)