0% found this document useful (0 votes)
10 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)
10 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

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