0% found this document useful (0 votes)
5 views2 pages

Basic Codes

The document presents ten different methods to print 'Hello Python' using Python programming techniques. These methods include basic print statements, functions, f-strings, format methods, string concatenation, lambda functions, class methods, list comprehensions, while loops, and generator functions. Each method is illustrated with code snippets for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Basic Codes

The document presents ten different methods to print 'Hello Python' using Python programming techniques. These methods include basic print statements, functions, f-strings, format methods, string concatenation, lambda functions, class methods, list comprehensions, while loops, and generator functions. Each method is illustrated with code snippets for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10 Ways to Write Hello Python

1. Basic print statement


print ( ” H e l l o Python ” )

2. Using a function
def s a y h e l l o ( ) :
print ( ” H e l l o Python ” )

say hello ()

3. Using f-string
name = ” Python ”
print ( f ” H e l l o {name}” )

4. Using format method


print ( ” H e l l o {} ” . format ( ” Python ” ) )

5. Using string concatenation


print ( ” H e l l o ” + ” Python ” )

6. Using lambda function


h e l l o = lambda : print ( ” H e l l o Python ” )
hello ()

1
7. Using a class method
class Greeter :
def g r e e t ( s e l f ) :
print ( ” H e l l o Python ” )

g = Greeter ()
g . greet ()

8. Using a list comprehension


[ print ( ” H e l l o Python ” ) f o r in range ( 1 ) ]

9. Using a while loop


i = 0
while i < 1 :
print ( ” H e l l o Python ” )
i += 1

10. Using a generator function


def h e l l o g e n ( ) :
y i e l d ” H e l l o Python ”

f o r g r e e t i n g in h e l l o g e n ( ) :
print ( g r e e t i n g )

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy