Writing First Python Program | Printing to Console in Python | Python Tutorials for Beginners #lec4

Jenny's Lectures CS IT
1 Sept 202213:04

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

00:00

💻 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.

05:03

🖌️ 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.

10:03

🔍 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

IDE stands for Integrated Development Environment. It is a software application that provides comprehensive facilities to programmers for software development. In the video, the instructor discusses using PyCharm as the IDE to write and run Python programs, emphasizing its features like syntax highlighting and auto-completion.

💡Python Interpreter

A Python interpreter is a program that reads and executes Python code. The interpreter converts the high-level code into machine-readable instructions. The video mentions installing Python 3.10.6 interpreter, which is necessary to run Python programs.

💡Print Function

The print function is a built-in Python function used to output text to the console. The video explains how to use the print function to display the classic 'Hello World' message, highlighting its simplicity compared to other programming languages.

💡Syntax

Syntax refers to the rules that define the structure of a programming language. The video covers Python syntax for the print function, showing how to use parentheses and quotation marks correctly. Syntax errors are discussed, including common mistakes like missing parentheses or quotes.

💡String

A string is a sequence of characters enclosed in quotes, used to represent text in programming. In the video, the instructor demonstrates how to print strings in Python using double quotes and explains the difference between strings and code.

💡Hello World

'Hello World' is a simple program that outputs 'Hello World' to the console. It is often the first program written when learning a new programming language. The video uses this example to introduce the basic syntax and usage of the print function in Python.

💡Error Handling

Error handling involves identifying and resolving errors in a program. The video discusses syntax errors, such as missing parentheses or quotes, and how the IDE helps by highlighting mistakes. The instructor shows how to debug these errors using error messages.

💡Python 2.x vs. 3.x

Python 2.x and 3.x are different versions of the Python language, with 3.x being the latest and supported version. The video explains the differences in the print statement between these versions, noting that Python 2.x does not use parentheses for print, while Python 3.x does.

💡Auto-completion

Auto-completion is a feature in IDEs that predicts and suggests code as you type, helping to write code faster and reduce errors. The video highlights this feature in PyCharm, showing how it assists with the print function's syntax.

💡Console

The console is an interface that allows users to interact with a program by typing commands and receiving text output. The video demonstrates using the console to run Python programs and view the output of the print function.

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

play00:00

so in the series of learning python

play00:02

programming language

play00:03

in the previous video we have discussed

play00:06

like how to download and install

play00:08

ide for python pycharm we have installed

play00:11

and

play00:12

python interpreter you can see python

play00:14

3.10.6 we have installed right so now i

play00:18

guess you're all set with your laptop

play00:20

you have python you have an id to write

play00:22

your programs right you have that

play00:24

interpreter also

play00:26

okay because python is an interpreted

play00:28

language so we have already

play00:30

now downloaded and installed a base

play00:32

interpreter for our python language

play00:35

i hope you have done this thing

play00:37

now in this video we'll see

play00:40

how to print something on console or you

play00:44

can say we will write our first program

play00:46

in python

play00:47

and what usually we do whenever you

play00:49

learn a new programming language the

play00:50

first program you write is you print

play00:53

that

play00:54

classical hello world

play00:56

on output screen on the console the same

play00:58

thing we will do we'll print hello world

play01:01

on the screen on the console

play01:03

right in python

play01:05

so

play01:06

to print like in c we use which function

play01:09

print a function in c plus plus we use c

play01:11

out to print something on the screen

play01:14

in python what do we use in python 3.10

play01:17

through point x

play01:19

version python 1.x python 2.x python 3.x

play01:23

but python 2.x version they have ended

play01:25

the support for python two point x uh

play01:28

version right two point one two point

play01:30

two like this

play01:31

now

play01:32

three point x we are working on three

play01:35

point ten basically the recent is three

play01:36

point ten point six

play01:38

so in this we have a function named

play01:41

print

play01:42

this is the function print

play01:46

so this we use to print something on the

play01:48

console

play01:49

okay

play01:50

now don't need to read and don't need to

play01:52

write any header file or anything or

play01:54

main function or anything

play01:56

simply you need to write

play01:58

what

play02:00

print whatever you want to print

play02:03

the string or you can say the string

play02:06

or whatever message you want to print

play02:08

that we will put here

play02:11

within these parentheses

play02:13

okay

play02:14

so i want to print hello world so simply

play02:17

in double quotes i'll write

play02:19

hello world

play02:24

that's it no semicolon nothing else

play02:27

if you will run this on your output

play02:29

screen you will get this program this

play02:31

output hello world

play02:33

if you don't print anything if simply

play02:36

you write print and you click on run

play02:40

on that file suppose i have a file the

play02:42

extension of python file is dot py right

play02:45

so

play02:46

we are simply running this thing

play02:49

empty parenthesis

play02:51

it's okay it will run

play02:54

what it will print just a blank line

play02:58

okay

play02:59

nothing would be shown just a blank line

play03:02

cursor would be here nothing would be

play03:03

shown

play03:05

if i want if you execute two print

play03:07

function then one and two two blank line

play03:09

would be shown something like this

play03:12

right

play03:14

so

play03:14

you can say it will

play03:16

the sprint function

play03:18

will produce

play03:19

an invisible new line

play03:22

character new line means add a new line

play03:24

so it will produce an invisible new line

play03:27

character

play03:29

because of that new line character we

play03:32

see

play03:32

you know

play03:33

a

play03:34

new blank line on your screen

play03:37

right i'll show you practically also

play03:39

now whatever you want to print you just

play03:41

write within these

play03:44

codes

play03:45

we let hello world simply write hello

play03:47

world so now let me do some experiment

play03:50

with this uh

play03:51

what you have to write down this how you

play03:53

can write down this thing if you don't

play03:55

put this closing

play03:58

codes what type of error you will get

play04:00

and these things let's just do practical

play04:03

on this

play04:04

uh print function and see before going

play04:06

to practical let me just this this is

play04:08

what in python the syntax is python in

play04:10

python 3 3.x in python two point x the

play04:14

previous uh versions

play04:16

print was just a statement it was not a

play04:19

function so what we used to write in

play04:21

that case print

play04:22

and

play04:24

hello world whatever you need to print

play04:26

you can just

play04:28

write down in these quotes so print

play04:30

hello world that's it no parenthesis

play04:33

so it was considered it was as a

play04:35

statement in python 2.x but here in

play04:38

python 3 it is

play04:40

a function so if you are using python 3

play04:43

point x version right then if you write

play04:45

something like this if you don't put

play04:47

these parentheses you will get

play04:49

error message syntax error message right

play04:52

if you are using python 2.x version you

play04:55

can write down print something like this

play04:56

so let's just do practical of this thing

play04:59

so we have opened our pycharm ide and

play05:02

let me just first

play05:04

change the color

play05:06

so you can go to file if you want to

play05:08

change if you are comfortable with this

play05:11

color you can go for this but i am not

play05:13

comfortable so go to setting

play05:15

and appearance in appearance just theme

play05:18

and

play05:19

i want

play05:20

either this this light

play05:22

or

play05:23

window 10 lite this one

play05:26

so you can go for any one

play05:28

from here you can set these themes okay

play05:32

so now let's change this color and

play05:35

just click ok now i guess you can see it

play05:38

clearly the code fine

play05:40

now

play05:41

we have created our first project in the

play05:43

previous video and first file first dot

play05:46

py okay

play05:47

if you want to create another file what

play05:49

you have to do in the first project on

play05:51

first project just click right click new

play05:54

and file and just name your file

play05:57

okay

play05:58

so i'm not going to create

play06:01

in the first dot py only extension is

play06:03

dot py

play06:04

we are printing so

play06:06

okay

play06:07

how to print just use the sprint

play06:09

function print

play06:12

fine let me just write down again p r i

play06:14

n t print and see it is showing you

play06:18

this is the you know beauty of this ide

play06:21

auto completion and see the print syntax

play06:24

it is showing here you can write down

play06:25

this values sap and file flash whatever

play06:28

these things that also one by one will

play06:30

be discussing but right now just if i

play06:33

just click enter

play06:35

it will give me like these parentheses

play06:38

automatically so now within these

play06:40

parentheses

play06:42

i'm adding

play06:44

hello

play06:46

world

play06:48

okay

play06:49

now let me just run this for you first

play06:52

see from here i have to select here main

play06:55

file is selected so i am going to select

play06:57

current file

play06:59

so current file is first dot py

play07:01

current file means i am working in this

play07:03

file and let's just or you can click in

play07:06

this

play07:07

this is the run button or you can just

play07:09

right click and

play07:11

this run first

play07:13

click on this

play07:14

okay now here

play07:16

it is going to run now and now it will

play07:18

print on your screen hello world first

play07:21

time you know it is taking some time

play07:23

because of the indexing and all

play07:25

so see you can see here hello world

play07:28

fine if i miss this semi-colon this

play07:33

sorry this um

play07:35

double quote closing double quote

play07:38

as you can see a red red underline

play07:41

means there is something

play07:43

wrong there is an error okay so this is

play07:46

what you can say uh

play07:49

this id will give you these kind of

play07:51

things if you use id this is you can see

play07:53

some features or

play07:55

some advantages of using id c missing

play07:58

closing codes

play08:00

so from here only you will come to know

play08:02

yeah you have missed quotes

play08:04

or if you run this

play08:05

here also you will get c now type of

play08:07

error c syntax error syntax error it is

play08:11

a syntax error

play08:12

so types of errors there are many types

play08:14

of error

play08:15

okay that also ah with these parallely

play08:18

with the code we will be seeing

play08:21

this is what syntax error syntax means

play08:23

what there are some rules to write

play08:26

programs in any you know programming

play08:29

language and those rules are known as

play08:31

syntax if you don't follow the syntax

play08:34

then

play08:36

it will give syntax error

play08:38

so now syntax or you can say like we

play08:40

have grammar rules

play08:42

okay

play08:43

same in programming language also we

play08:45

have some rules to write down these

play08:47

programs so these are syntax known as

play08:49

syntax

play08:50

if now it is syntax error because syntax

play08:53

is what in print

play08:55

whatever string the message which is not

play08:58

a code actually

play08:59

see print is a code it will do something

play09:01

it will tell the interpreter to do

play09:03

something but this hello world is

play09:06

rather than hello world i can write

play09:07

jenny's lectures i can write

play09:09

anything else like you are the best

play09:12

so this is just a message it's not a

play09:14

code

play09:16

so other than the code whatever you

play09:18

write the message or the string that we

play09:19

will put in

play09:21

quotes

play09:22

okay single quotes as well as double

play09:24

quotes that also will discuss when to

play09:26

put single code when to put double quote

play09:28

okay now right now i'm putting double

play09:30

quote because actually i am from c and c

play09:32

plus background so

play09:34

to write down string i used to put the

play09:36

string the sequence of character as a

play09:38

string in double quotes

play09:40

okay

play09:41

so now see syntax error it will give

play09:43

syntax error unterminated string literal

play09:46

hello world this is a string literal it

play09:48

is unterminated you haven't terminated

play09:50

this thing detected at line number one

play09:53

line number one

play09:55

this is also a skill to identify what is

play09:58

the error type of error in which line at

play10:01

all

play10:02

okay

play10:03

so you have to you know learn this thing

play10:05

also parallel

play10:08

okay now see you can see one arrow here

play10:10

you have

play10:11

started this string literal but you

play10:13

haven't terminated here in line number

play10:15

one

play10:16

or if you are not getting what is the

play10:18

error just simply

play10:20

the error then text error this thing

play10:22

copy this thing

play10:24

open your google

play10:25

paste that

play10:26

and just click enter

play10:28

okay or more specifically you can write

play10:31

this error in python in whatever

play10:32

programming language you are

play10:34

you know practicing you're learning

play10:38

so generally first you know that link

play10:40

would be from stack overflow so there

play10:42

someone has already asked this type of

play10:43

questions and you will get many answers

play10:45

simple okay so now let's just first what

play10:50

you have to do

play10:51

close this now see after closing

play10:54

this is what

play10:56

syntax highlighting also you need to

play10:57

know the sprint is what in black the

play11:00

string is what in

play11:01

green

play11:03

this hello world plus these codes in

play11:05

green color okay and if you miss this

play11:08

and these

play11:09

ah what you can say

play11:12

so the sprint is what in not in black

play11:15

it's in blue and these parentheses are

play11:18

in black so if you remove this double

play11:21

quote from here this parenthesis and the

play11:23

ending of the parentheses parenthesis

play11:24

this is also in green color so there is

play11:26

something wrong you can identify

play11:28

okay

play11:30

okay now put this one and just

play11:33

run this again so it will print now

play11:35

hello world whatever you want to print

play11:36

you can print now if you don't put this

play11:39

parenthesis

play11:41

will give an error see you can see the

play11:43

red underline here again

play11:45

okay let me just run this

play11:47

and it will give again some error see it

play11:50

is giving syntax error missing

play11:52

parenthesis in call to print

play11:55

did you mean this print you are calling

play11:58

print calling means print is a function

play11:59

so we are calling print but missing

play12:01

parenthesis missing parenthesis

play12:03

because we are using three point

play12:04

exposures and so

play12:06

here you have to put

play12:08

these parentheses

play12:09

okay

play12:11

now

play12:12

okay what you need to do blank print you

play12:15

can call

play12:16

see

play12:17

blank print also you can call it will

play12:20

not print nothing but a blank line it

play12:22

will call an individual new line

play12:25

character so again if i write print

play12:29

and call

play12:31

you will see two blank new line same

play12:33

three four five print plan you will call

play12:36

these blank line would be increased like

play12:38

this i hope now print is clear to you

play12:41

now in next video i'll

play12:43

discuss a coding exercise with you guys

play12:46

okay

play12:47

so i hope every point about print

play12:48

function is clear to you guys how to

play12:50

write down your first program how to

play12:52

print something on console in python now

play12:54

in the next video we will see a coding

play12:56

exercise related to this print function

play12:58

right so i'll see you in the next video

play13:00

till then bye take

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
Python BasicsCoding TutorialPrint FunctionPyCharm IDEProgramming 101Beginner PythonHello WorldPython 3Code ExecutionSyntax Error
¿Necesitas un resumen en inglés?