Home
Tools
Workshops
Technologies
Pricing
Contact Us



Meeting Uncle Print

Day-1 of A Month in the Python's Cave

getting started with meteor
Uncle Print is Simple and Easy
Just open your favourite text editor and start coding in a file named Print.py or alternatively you can try all the commands in python interactive shell and later on add them to a file.
Start with the Code!
Use the following command in an Interactive Python shell to see results instantly.

1. print a simple greeting


print 'Hello Uncle Print, I am very happy to be here'

2. print with a newline '\n' escape character


print 'Hello Uncle Print. \nI am very happy to be here'

3. print with a apostrophe \' escape character


print 'I\'m so happy to be in Python\'s cave'

4. print strings in concatenation


print '%s %s %s' %('I','am','combining strings')

5. print strings with integers


print '%s %d' %('remember everything starts with a ', 0)

6. print strings with floats


print '%s %f %s' %('value of pi i.e.', 3.14, 'is just another scientific opinion')

7. print numbers using a specific length by padding spaces in front


print '%s %4d' %('the number with a length of 4 is', 25

8.print floats to a certain decimal places


print '\n%s %4.2f' %('float with length 4 printed to 2 decimal places: ', 2.5051995)

9. print signed numbers 'negative numbers'


print '% d' % (- 122)

10. print signed numbers 'positive numbers'


print '%+d' % (14)

Putting things together!
we can add all the above command in a single file Print.py and run it to see the results.

# print a simple greeting 
print 'Hello Uncle Print, I am very happy to be here'

# print with a newline escape character 
print '\nHello Uncle Print. \nI am very happy to be here'

# print with a apostrophe escape character
print '\nI\'m so happy to be in Python\'s cave'

# print strings in concatenation
print '\n%s %s %s' %('I','am','combining strings')

# print strings with integers 
print '\n%s %d' %('remember everything starts with a ', 0)

# print strings with floats 
print '\n%s %f %s' %('value of pi i.e.', 3.14, 'is just another scientific opinion')

# print numbers using a specific length by padding space in front
print '\n%s %4d' %('the number with a length of 4 is', 25)

# print floats to a certain decimal places 
print '\n%s %4.2f' %('float with length 4 printed to 2 decimal places: ', 2.5051995)

# print signed numbers 'negative numbers'
print '\n% d' % (- 122)

# print signed numbers 'positive numbers'
print '\n%+d' % (14)
you can run your Print.py using the following command.

>python Print.py
you should see an output similar to the following.

Hello Uncle Print, I am very happy to be here

Hello Uncle Print.
I am very happy to be here

I'm so happy to be in Python's cave

I am combining strings

remember everything starts with a  0

value of pi i.e. 3.140000 is just another scientific opinion

the number with a length of 4 is   25

float with length 4 printed to 2 decimal places:  2.51

-122

+14

Congratulations! You've learned your first skill at the Python's Cave i.e. using the Python print command in 10 different scenarios.
PythonCave on Github
We've created a repository on github to keep pushing new code. In case you're enthusiastic about it, following is link to that repository.




developed & nourished with by rishabh.io