matplotlib
template <typename T>
_Defer<void(*(PID<T>, void (T::*)(void)))
(const PID<T>&, void (T::*)(void))>
defer(const PID<T>& pid, void (T::*method)(void))
{
void (*dispatch)(const PID<T>&, void (T::*)(void)) =
&process::template dispatch<T>;
return std::tr1::bind(dispatch, pid, method);
}
print("Hello world")
import requests
resp = [Link]("[Link]
html = [Link]
print(html[205:294])
<title>Python Tutorials – Real Python</title>
<meta name="author" content="Real Python">
#include <stdio.h>
int main(void)
{
printf("Hello, world\n");
}
Hello, world
print("Hello, world")
# This is Python code:
print("Hello world!")
$ # This is a terminal command:
$ python [Link]
>>>
Cmd+Spacebar
idle Return
>>>
$ python --version
$ python3 --version
$ python3 --version
Python 3.7.2
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
Release
$ sudo apt-get update
$ sudo apt-get install python3.7 idle-python3.7
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.7 idle-python3.7
python3 --version 3.7
python3.7 --version
$ idle3
3.7 idle3
$ idle-python3.7
>>>
Python 3.7.2 (default, Dec 25 2018, [Link])
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
>>>
1 + 1
Enter
Enter
2
>>> 1 + 1
2
>>>
>>>
>>>
print()
r
print()
print() print
"Hello, world"
>>> print("Hello, world")
Hello, world
"Hello, world"
print()
"Hello,
world"
print("Hello, world")
>>>
hello_-
[Link] .py
.py
.py
Hello, world
Hello, world
F5
>>> =================== RESTART ===================
.py
Ctrl-Click
hello_world.py
print("Hello, world)
"Hello, world"
EOL while scanning string literal.
"Hello, world"
"Hello,
world
hello_world.py
print(Hello, world)
"Hello, world"
Hello, world
Traceback (most recent call last):
File "/home/hello_world.py", line 1, in <module>
print(Hello, world)
NameError: name 'Hello' is not defined
NameError
print(Hello, world)
name 'Hello' is not defined
NameError
Hello,
world
Hello world
print
Hello world
hello_world.py
phrase = "Hello, world"
print(phrase)
phrase
"Hello, world" = phrase
print()
=
=
hello_word.py
print()
Hello, world
print()
print("phrase")
phrase
phrase
Phrase = "Hello, world"
print(phrase)
Phrase
phrase phrase
NameError
Phrase phrase
print()
print() Print()
phrase string1 _a1p4a list_of_names
9lives
myPhrase listOfNames
myPhrase my_phrase
listOfNames list_of_names
print()
print()
print()
>>> my_phrase = "Hello, world"
>>> my_phrase
Enter my_phrase
'Hello, world'
"Hello, world"
print(my_phrase)
>>> print(my_phrase)
Enter
Hello, world
my_phrase Enter
my_phrase
my_phrase
"Hello, world"
print()
>>> x = 2
>>> x
2
>>> print(x)
2
print()
print()
x = 2 y = "2" print(x)
print(y) x y
>>> x = 2
>>> y = "2"
>>> print(x)
2
>>> print(y)
2
>>> x
2
>>> y
'2'
print()
Enter
print Enter
>>> print
<built-in function print>
my_phrase = "Hello, world"
my_phrase
#
hello_world.py
# This is my first script
phrase = "Hello, world."
print(phrase) # This line displays "Hello, world"
phrase
#
print("#1")
# Print "Hello, world"
print("Hello, world")
# Calculate the area of a rectangle
area = 10 * 5
'''
"""
''' """
''' """
hello_world.py
"""
This is my first script.
It prints the phrase "Hello, world."
The comments are longer than the script!
"""
phrase = "Hello, world."
print(phrase)
"""
#
SyntaxError
print("Hello, world") """This is
an invalid comment"""
print()
=
#
''' """
string1 = 'Hello, world.'
string2 = "We're #1!"
string3 = "1234"
string4 = 'I said, "Put it over by the llama."'
string1 string4 string2
string3 string2 string4
"We're
#1" ' 'I said,
"Put it over by the llama."'
>>> text = "She said "What time is it?""
File "<stdin>", line 1
text = "She said "What time is it?""
^
SyntaxError: invalid syntax
SyntaxError
"
string2
# string3
"×Pýŧħøŋ×"
\
paragraph = "This planet has - or rather had - a problem, which was \
this: most of the people living on it were unhappy for pretty much \
of the time. Many solutions were suggested for this problem, but \
most of these were largely concerned with the movements of small \
green pieces of paper, which is odd because on the whole it wasn't \
the small green pieces of paper that were unhappy."
""" '''
paragraph = """This planet has - or rather had - a problem, which was
this: most of the people living on it were unhappy for pretty much
of the time. Many solutions were suggested for this problem, but
most of these were largely concerned with the movements of small
green pieces of paper, which is odd because on the whole it wasn't
the small green pieces of paper that were unhappy."""
print(paragraph)
>>> print("""This is a
... string that spans across multiple lines
... that also preserves whitespace.""")
This is a
string that spans across multiple lines
that also preserves whitespace.
+
>>> string1 = "abra"
>>> string2 = "cadabra"
>>> magic_string = string1 + string2
>>> magic_string
'abracadabra'
string1 string2 +
magic_string
>>> first_name = "Jean-Luc"
>>> last_name = "Picard"
>>> full_name = first_name + " " + last_name
>>> full_name
'Jean-Luc Picard"
first_name last_name
first_name " "
last_name
print()
>>> print("abra", "ca", "dabra")
abra ca dabra
print()
"abc"
"make it so"
len()
>>> len("abc")
3
len()
>>> my_string = "abc"
>>> string_length = len(my_string)
>>> string_length
3
"abc" my_string len()
my_string
string_length string_length
my_string
len() len() my_-
string
print()
[ ]
( )
[ ]
{ }
>>> flavor = "apple pie"
>>> flavor[3]
'l'
flavor[3] "apple pie"
"l" 'p' "apple pie"
'a'
"apple pie" 'p' 'p'
'l'
>>> flavor[0]
'a'
"apple pie"
a p p l e p i e
0 1 2 3 4 5 6 7 8
>>> flavor[13]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
IndexError
"apple pie"
>>> flavor[-1]
'e'
"apple pie" "e"
"apple pie"
a p p l e p i e
-9 -8 -7 -6 -5 -4 -3 -2 -1
flavor = "apple pie"
>>> first_three_letters = flavor[0] + flavor[1] + flavor[2]
>>> first_three_letters
'app'
>>> flavor = "apple pie"
>>> flavor[0:3]
'app'
flavor[0:3]
flavor
[0:3]
flavor[0:3]
flavor "apple
pie"
>>> flavor = "apple pie"
>>> flavor[:5]
'apple'
>>> flavor[5:]
' pie'
>>> flavor[:]
'apple pie'
>>> flavor[:-5]
'appl'
>>> flavor[-5:]
'e pie'
>>> flavor[-8:-5]
'ppl'
IndexError
>>> flavor[:14]
'apple pie'
>>> flavor[13:15]
''
flavor
"apple pie"
flavor[13:15]
""
>>> my_string = "goal"
>>> my_string[0] = "f" # This won't work!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
TypeError str
str
"goal" "foal"
"f"
"goal"
>>> my_string = "goal"
>>> my_string = "f" + my_string[1:]
>>> my_string
'foal'
"goal" my_string
my_string[1:] "oal" "f"
"foal"
:
len()
print()
"zing"
"bazinga"
.lower()
.lower()
>>> "Arthur Dent".lower()
'arthur dent'
.
lower ()
print() len()
.lower()
>>> name = "Arthur Dent"
>>> [Link]()
'arthur dent'
.lower() .upper()
>>> loud_voice = "Can you hear me yet?"
>>> loud_voice.upper()
'CAN YOU HEAR ME YET?'
.upper() .lower()
len()
len()
loud_voice len()
>>> len(loud_voice)
20
.upper() .lower()
. .lower() .upper()
loud_voice.upper()
.upper()
.rstrip() .lstrip() .strip()
.rstrip()
>>> name = "Arthur Dent "
>>> name
'Arthur Dent '
>>> [Link]()
'Arthur Dent'
"Arthur Dent "
.rstrip()
"Arthur Dent"
.lstrip() .rstrip()
>>> name = " Arthur Dent"
>>> name
' Arthur Dent'
>>> [Link]()
'Arthur Dent'
.strip()
>>> name = " Arthur Dent "
>>> name
' Arthur Dent '
>>> [Link]()
'Arthur Dent'
.rstrip() .lstrip() .strip()
.startswith()
.endswith()
"Enterprise"
.startswith()
"e" "n"
>>> starship = "Enterprise"
>>> [Link]("en")
False
.startswith()
"Enterprise"
"e" "n" .startswith("en")
False
.startswith("en") False "En-
terprise" "E"
.startswith() .startswith()
True "En"
>>> [Link]("En")
True
.endswith()
>>> [Link]("rise")
True
.startswith() .endswith()
>>> [Link]("risE")
False
True False
.upper() .lower()
>>> name = "Elena"
>>> [Link]()
'ELENA'
>>> name
'Elena'
[Link]() name
>>> name = "Elena"
>>> name = [Link]()
>>> name
'ELENA'
[Link]() "ELENA"
name "Elena"
"name"
>>> my_string = "kerfuffle"
my_string Enter
>>> my_string.
Ctrl+Space
Tab
my_string.u Tab
my_string.upper
my_string
my_string
my_string
"An-
imals" "Badger" "Honey Bee" "Honeybadger"
string1 = " Filet Mignon"
string2 = "Brisket "
string3 = " Cheeseburger "
.startswith("be")
string1 = "Becomes"
string2 = "becomes"
string3 = "BEAR"
string4 = " bEautiful"
.startswith("be")
True
input()
input()
input()
input()
Enter input()
input()
prompt = "Hey, what's up? "
user_input = input(prompt)
print("You said:", user_input)
Hey, what's up?
"Hey, what's up "
Enter
user_input
Hey, what's up? Mind your own business.
You said: Mind your own business.
.upper()
response = input("What should I shout? ")
response = [Link]()
print("Well, if you insist...", response)
first_letter.py
Tell me your password:
"no"
The first letter you entered was: N
Enter
input()
>>> num = "2"
>>> num + num
'22'
+
"2" + "2" "22" "4"
>>> num = "12"
>>> num * 3
'121212'
num * 3 "12"
"121212"
"12" * 3 = "12" + "12" +
"12" n
n
num * 3
>>> 3 * num
'121212'
*
"12" * "3" En-
ter
>>> "12" * "3"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'str'
TypeError
*
>>> "3" + 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
TypeError +
"3" + 3 6
"3"
TypeError
num = input("Enter a number to be doubled: ")
doubled_num = num * 2
print(doubled_num)
input()
num "2" 2
num * 2 "2"
"22"
int() float()
int()
float()
>>> int("12")
12
>>> float("12")
12.0
float()
>>> int("12.0")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '12.0'
num = input("Enter a number to be doubled: ")
doubled_num = num * 2
print(doubled_num)
doubled_num = num * 2 num
2 num
int() float()
num
num = input("Enter a number to be doubled: ")
doubled_num = float(num) * 2
print(doubled_num)
TypeError
>>> num_pancakes = 10
>>> "I am going to eat " + num_pancakes + " pancakes."
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
num_pancakes
"I'm going to eat"
num_pancakes str()
>>> num_pancakes = 10
>>> "I am going to eat " + str(num_pancakes) + " pancakes."
'I am going to eat 10 pancakes.'
str()
>>> "I am going to eat " + str(10) + " pancakes."
'I am going to eat 10 pancakes.'
str()
>>> total_pancakes = 10
>>> pancakes_eaten = 5
>>> "Only " + str(total_pancakes - pancakes_eaten) + " pancakes left."
"Only 5 pancakes left."
str()
>>> str(print)
'<built-in function print>'
>>> str(int)
"<class 'int'>"
>>> str(float)
"<class 'float'>"
str()
int()
float()
str()
input()
The product of 2 and 4 is 8.0.