- No semicolon in Python!
- Wrong!
You can use semicolon to execute more than 1 statements in one line.
import pdb; pdb.set_trace()
equivalent to:
import pdb
pdb.set_trace()
- Wrong!
You can use semicolon to execute more than 1 statements in one line.
import pdb; pdb.set_trace()
equivalent to:
import pdb
pdb.set_trace()
Why is it called python programming language?
It is due to the fact that the creator, Guido Van Rossum really liked “Monty Python’s Flying Circus”.
Actually it was a popular comedy in 1970s.
It is due to the fact that the creator, Guido Van Rossum really liked “Monty Python’s Flying Circus”.
Actually it was a popular comedy in 1970s.
there is no bigger number than float('Inf')
> 2**42 > float('Inf')
False
# and negative infinity is float('-Inf')
> 2**42 > float('Inf')
False
# and negative infinity is float('-Inf')
#PrettyPrint
To see data with visual indentation, use pprint instead of print
from pprint import pprint
pprint(data)
To see data with visual indentation, use pprint instead of print
from pprint import pprint
pprint(data)
Have you ever forgotten to reference to a variable in Interactive Shell?
ignored returns are referenced to _
> from requests import get
> get('http://example.com')
# Oh no, forgot to reference
> response = _
> response
<Response [200]>
ignored returns are referenced to _
> from requests import get
> get('http://example.com')
# Oh no, forgot to reference
> response = _
> response
<Response [200]>
You don't have to write hello world anymore
Just import it!
> import __hello__
Hello world!
Just import it!
> import __hello__
Hello world!
Have you tried this?
# -*- encoding: nocolon -*-
for item in items
with open('output.txt', 'r') as f
f.write(item)
# -*- encoding: nocolon -*-
for item in items
with open('output.txt', 'r') as f
f.write(item)
When you want count elements of a list or letters of string use this:
> from collections import Counter
> c = Counter(["a", "b", "c", "a", "a"])
> c["a"]
3
> c["b"]
1
> c["d"]
0
> from collections import Counter
> c = Counter(["a", "b", "c", "a", "a"])
> c["a"]
3
> c["b"]
1
> c["d"]
0
To find out from where module got imported use this:
>import os
>os.__file__
'/usr/lib/python3.5/os.py'
Note that __file__ is created in every python file automatically.
if you have main.py, it will give full path to file.
print("ran the code", __file__)
>import os
>os.__file__
'/usr/lib/python3.5/os.py'
Note that __file__ is created in every python file automatically.
if you have main.py, it will give full path to file.
print("ran the code", __file__)
Need Calendar? Import it!
import calendar
# monthly
print(calendar.moth(2018, 9))
# yearly
print(calendar.calendar(2018))
import calendar
# monthly
print(calendar.moth(2018, 9))
# yearly
print(calendar.calendar(2018))
8 World-Class Software Companies That Use Python:
Google
- Python where we can, C++ where we must
Facebook
- for Facebook Ads API
Instagram
- uses Django Web Framework
Spotify
- for data analysis and back end services
Quora
- they decided not to go with C#
Netflix
- for RESTful web app
Dropbox
- Guido van Rossum worked there
Reddit
- originally ran the site with web.py
- Python where we can, C++ where we must
- for Facebook Ads API
- uses Django Web Framework
Spotify
- for data analysis and back end services
Quora
- they decided not to go with C#
Netflix
- for RESTful web app
Dropbox
- Guido van Rossum worked there
- originally ran the site with web.py
# sets
>x1 = {'foo', 'bar', 'baz'}
>x2 = {'baz', 'qux', 'quux'}
>x1 | x2 # same as x1.union(x2)
{'baz', 'quux', 'qux', 'bar', 'foo'}
> x1 & x2 # x1.intersection(x2)
{'baz'}
> x1 - x2 # x1.difference(x2)
{'foo', 'bar'}
> x1 ^ x2 # x1.symmetric_difference(x2)
{'foo', 'qux', 'quux', 'bar'}
>x1 = {'foo', 'bar', 'baz'}
>x2 = {'baz', 'qux', 'quux'}
>x1 | x2 # same as x1.union(x2)
{'baz', 'quux', 'qux', 'bar', 'foo'}
> x1 & x2 # x1.intersection(x2)
{'baz'}
> x1 - x2 # x1.difference(x2)
{'foo', 'bar'}
> x1 ^ x2 # x1.symmetric_difference(x2)
{'foo', 'qux', 'quux', 'bar'}
To run python code without entering interactive shell for quick check or calculation, use -c flag
$ python -c "print(42**2)"
1764
$ python -c "print(42**2)"
1764
Python was once offered to be used for interactive web pages (insted of js) if and only if it adopted curly braces instead of indentations.
To know what Guido responed, run:
>from __future__ import braces
To know what Guido responed, run:
>from __future__ import braces
> import numpy as np # is equivalent to
> np = __import__("numpy")
"""
import implements __import__ just as:
str implemens __str__
repr implements __repr__
len implements __len__, you get the idea
"""
> np = __import__("numpy")
"""
import implements __import__ just as:
str implemens __str__
repr implements __repr__
len implements __len__, you get the idea
"""
Forwarded from GDG Tashkent (Dostonkhon Ozodkhujaev)
Meet Azimjon Pulatov, who completed Google Cloud Study Jam Challenge and got his brand new Google Home Mini today! 👏
The challenge is still on, so don't miss your chance to both learn a new skill and obtain a pleasant gift from Google!
Finish all 10 quests to complete the challenge. Submit your profile to get a Google Home Mini!
More information about the challenge at:
events.withgoogle.com/cloud-study-jam-challenge
@gdgtashkent
The challenge is still on, so don't miss your chance to both learn a new skill and obtain a pleasant gift from Google!
Finish all 10 quests to complete the challenge. Submit your profile to get a Google Home Mini!
More information about the challenge at:
events.withgoogle.com/cloud-study-jam-challenge
@gdgtashkent