100% found this document useful (1 vote)
456 views

DevOps Bootcamp Notes 2023 Edition

Uploaded by

Aditya Tidke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
456 views

DevOps Bootcamp Notes 2023 Edition

Uploaded by

Aditya Tidke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1433

Why Linux?

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
2
https://insights.stackoverflow.com/survey/2019
Why Linux?

2013 - Docker was born


2016– Docker for Windows was born

https://docs.ansible.com/ansible/latest/user_guide/windows_faq.html

Kubernetes Documentation
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Linux Basics

• Linux CLI
• VI Editor
• Package Management
• Service Management

Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg


© Copyright K odeK l oud *Allowed multiple selections
Linux Basics Course www.kodekloud.com

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
just enough

LINUX

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Shell Types
echo $SHELL Broune Shell (Sh Shell)
/bin/bash

C Shell (csh or tcsh)

Z Shell (zsh)

Bourne again Shell (bash)

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Basic Commands
echo Hi
Print to screen
Hi

ls
List files & folders
File.txt my_dir1 file2.conf

cd my_dir1 Change directory

pwd
Present Working Directory
/home/my_dir1

mkdir new_directory Make Directory

cd new_directory; mkdir www; pwd Multiple commands


/home/my_dir1/new_directory
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Commands - Directories
/tmp/asia/india/bangalore
mkdir /tmp/asia
mkdir /tmp/asia/india
mkdir /tmp/asia/india/bangalore Make Directory Hierarchy

mkdir –p /tmp/asia/india/bangalore

rm –r /tmp/my_dir1 Remove Directory

cp –r my_dir1 /tmp/my_dir1 Copy Directory

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Commands - Files
touch new_file.txt
Create a new file (no contents)
Hi

cat > new_file.txt


Add contents to file
This is some sample contents
CTLR + D

cat new_file.txt
View contents of file
This is some sample contents

cp new_file.txt copy_file.txt Copy File

mv new_file.txt sample_file.txt Move (Rename) File

rm new_file.txt Remove (Delete) File


© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Labs
• NOTE: These labs should NOT have the user require to use sudo
• Have a file and folder tree structure created. Ask MCQ questions (only based on the
previous slides) to users, such as
• Identify number of files and directories in a path
• What is a file not present in a directory
• Navigate to some directory(don’t specify the full path) and ask user to find the present working
directory
• Ask user to perform operations
• Create empty file
• Create file with some content
• Create directory
• Create directory hierarchy
• Copy file to a different place (Stage a file with some data)
• Copy directory
• Remove file
• Remove directory and all contents
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just a bit more

LINUX

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
User Accounts
whoami
matthew
matthew

id
uid=1001(matthew) gid=1001(matthew) groups=1001(matthew)

su aparna
Password:

ssh [email protected]

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
14
User Accounts
ls /root
ls: cannot open directory /root: Permission denied
matthew root
sudo ls /root SUDO
anaconda-ks.cfg initial-setup-ks.cfg /etc/sudoers

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
15
Download Files
curl http://www.some-site.com/some-file.txt -O
some-file.txt

wget http://www.some-site.com/some-file.txt -O some-file.txt


some-file.txt

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check OS Version
ls /etc/*release*
/etc/centos-release /etc/os-release /etc/system-release
/etc/centos-release-upstream /etc/redhat-release /etc/system-release-cpe

cat /etc/*release*
CentOS Linux release 7.7.1908 (Core)
Derived from Red Hat Enterprise Linux 7.7 (Source)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
• Wget
• Curl
• Cat /etc/*release*

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
18
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
Package Managers

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
RPM (Red Hat Package Manager)
rpm –i telnet.rpm Install Package

rpm –e telnet.rpm Uninstall Package

rpm –q telnet.rpm Query Package

?
?
? RPM
? telnet.rpm
ansible
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
YUM
yum install ansible Install Package

/etc/yum.repos.d

PyYAML
YUM

python RPM
ansible
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

sshpass
YUM Repos
yum repolist
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10097
extras/7/x86_64 CentOS-7 - Extras 341
mongodb-org-4.2/7 MongoDB Repository 25
mysql-connectors-community/x86_64 MySQL Connectors Community 141
mysql-tools-community/x86_64 MySQL Tools Community 105
mysql80-community/x86_64 MySQL 8.0 Community Server 161
updates/7/x86_64 CentOS-7 - Updates 1787

ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Media.repo mysql-community.repo
CentOS-CR.repo CentOS-Sources.repo mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-fasttrack.repo mongodb-org-4.2.repo

cat /etc/yum.repos.d/CentOS-Base.repo
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
YUM
yum list ansible
Installed Packages
ansible.noarch 2.9.6-1.el7 @epel

yum remove ansible

yum --showduplicates list ansible


Available Packages
ansible.noarch 2.4.2.0-2.el7 extras
ansible.noarch 2.9.6-1.el7 epel

yum install ansible-2.4.2.0

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Labs

• View installed packages


• Identify versions of installed packages
• Install specific packages using yum
• Install specific packages using yum with specific versions
• Remove packages

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright K odeK l oud


Services

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
service httpd start Start HTTPD service
Or
systemctl start httpd Start HTTPD service

systemctl stop httpd Stop HTTPD service

systemctl status httpd Check HTTPD service Status

Configure HTTPD to start at


systemctl enable httpd startup

Configure HTTPD to not start at


systemctl disable httpd startup
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Services
/usr/bin/python3 /opt/code/my_app.py systemctl start my_app
* Serving Flask app "my_app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment. systemctl stop my_app
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

/etc/systemd/system
curl http://localhost:5000
Hello, World!

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
/usr/bin/python3 /opt/code/my_app.py
/usr/bin/python3 /opt/code/my_app.py my_app.service
* Serving Flask app "my_app" (lazy loading)
* Environment: production [Service]
WARNING: This is a development server. Do not use it in a production deployment. ExecStart=
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

systemctl daemon-reload
curl http://localhost:5000
Hello, World!
systemctl start my_app

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py

Apr 07 09:01:39 systemd[1]: Started my_app.service.


Apr 07 09:01:39 python3[5038]: * Serving Flask app "my_app" (lazy loading) systemctl daemon-reload
Apr 07 09:01:39 python3[5038]: * Environment: production
Apr 07 09:01:39 python3[5038]: WARNING: This is a development server. Do not use it in a produ...ent.
Apr 07 09:01:39 python3[5038]: Use a production WSGI server instead.
Apr 07 09:01:39 python3[5038]: * Debug mode: off systemctl start my_app
Apr 07 09:01:39 python3[5038]: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Hint: Some lines were ellipsized, use -l to show in full.
systemctl stop my_app

curl http://localhost:5000
Hello, World!
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py

Apr 07 09:01:39 systemd[1]: Started my_app.service. [Install]


Apr 07 09:01:39 python3[5038]: * Serving Flask app "my_app" (lazy loading) WantedBy=multi-user.target
Apr 07 09:01:39 python3[5038]: * Environment: production
Apr 07 09:01:39 python3[5038]: WARNING: This is a development server. Do not use it in a produ...ent.
Apr 07 09:01:39 python3[5038]: Use a production WSGI server instead.
Apr 07 09:01:39 python3[5038]: * Debug mode: off
Apr 07 09:01:39 python3[5038]: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) systemctl daemon-reload
Hint: Some lines were ellipsized, use -l to show in full.

systemctl start my_app

systemctl stop my_app


curl http://localhost:5000
Hello, World!
© Copyright K odeK l oud systemctl enable my_app
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Unit]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago Description=My python web application
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
[Service]
Apr 07 09:01:39 systemd[1]: Started my_app.service.
ExecStart= /usr/bin/python3 /opt/code/my_app.py
Apr 07 09:01:39 python3[5038]: * Serving Flask app "my_app" (lazy loading) ExecStartPre=/opt/code/configure_db.sh
Apr 07 09:01:39 python3[5038]: * Environment: production
Apr 07 09:01:39 python3[5038]: WARNING: This is a development server. Do not use it in a produ...ent. ExecStartPost=/opt/code/email_status.sh
Apr 07 09:01:39 python3[5038]: Use a production WSGI server instead.
Apr 07 09:01:39 python3[5038]: * Debug mode: off
Apr 07 09:01:39 python3[5038]: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) [Install]
Hint: Some lines were ellipsized, use -l to show in full.
WantedBy=multi-user.target

curl http://localhost:5000 systemctl daemon-reload


Hello, World!
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
systemctl start my_app
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Unit]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago Description=My python web application
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
[Service]
Apr 07 09:01:39 systemd[1]: Started my_app.service.
ExecStart= /usr/bin/python3 /opt/code/my_app.py
Apr 07 09:01:39 python3[5038]: * Serving Flask app "my_app" (lazy loading) ExecStartPre=/opt/code/configure_db.sh
Apr 07 09:01:39 python3[5038]: * Environment: production
Apr 07 09:01:39 python3[5038]: WARNING: This is a development server. Do not use it in a produ...ent. ExecStartPost=/opt/code/email_status.sh
Apr 07 09:01:39 python3[5038]: Use a production WSGI server instead.
Apr 07 09:01:39 python3[5038]: * Debug mode: off
Restart=always
Apr 07 09:01:39 python3[5038]: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Hint: Some lines were ellipsized, use -l to show in full.
[Install]
WantedBy=multi-user.target

curl http://localhost:5000 systemctl daemon-reload


Hello, World!
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
systemctl start my_app
Service Unit File - Docker
/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
Networking Basics

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Networking Pre-Requisite
• Switching
• Routing
• Default Gateway
• DNS Configuration on Linux

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Switching ??

A eth0 eth0 B

192.168.1.0

192.168.1.10 192.168.1.11

ip link ip link
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
fq_codel state UP mode DEFAULT group default qlen 1000 fq_codel state UP mode DEFAULT group default qlen 1000

ip addr add 192.168.1.10/24 dev eth0 ip addr add 192.168.1.11/24 dev eth0

ping 192.168.1.11
© Copyright KodeKloud
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Routing ??

A eth0 eth0 B C eth0 eth0 D


192.168.1.0 192.168.2.0

192.168.1.10 192.168.1.11 192.168.2.10 192.168.2.11

192.168.1.1 192.168.2.1

© Copyright K odeK l oud


Gateway

A eth0 eth0 B C eth0 eth0 D


192.168.1.0 192.168.2.0

192.168.1.10 192.168.1.11 192.168.2.10 192.168.2.11

192.168.1.1 192.168.2.1

route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface

ip route add 192.168.2.0/24 via 192.168.1.1


route
Kernel IP routing table
Destination
© Copyright KodeKloud Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
Gateway

A eth0 eth0 B C eth0 eth0 D


192.168.1.0 192.168.2.0

192.168.1.10 192.168.1.11 192.168.2.10 192.168.2.11

192.168.1.1 192.168.2.1

ip route add 192.168.1.0/24 via 192.168.2.1


route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
© Copyright KodeKloud
Default Gateway INTERNET

172.217.194.0
INTERNET

216.134.45.0
INTERNET

16.44.53.0

A eth0 eth0 B C eth0 eth0 D


192.168.1.0 192.168.2.0

192.168.1.10 192.168.1.11 192.168.2.10 192.168.2.11

192.168.1.1 192.168.2.1

ip route add 192.168.1.0/24 via 192.168.2.1

ip
iproute
routeadd
add172.217.194.0/24 via 192.168.2.1
default via 192.168.2.1

route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
© Copyright KodeKloud
172.217.194.0
0.0.0.0 192.168.2.1
192.168.2.1 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
default
192.168.2.0 192.168.2.1
0.0.0.0 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
Default Gateway INTERNET

172.217.194.0
INTERNET

216.134.45.0
INTERNET

16.44.53.0

A eth0 eth0 B C eth0 eth0 D


192.168.1.0 192.168.2.0

192.168.1.10 192.168.1.11 192.168.2.10 192.168.2.11

192.168.2.1
192.168.1.1

192.168.2.2

ip route add 192.168.1.0/24 via 192.168.2.2

route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0
default 192.168.2.1
192.168.2.1 255.255.255.0
255.255.255.0 UG 0 0 0 eth0
© Copyright K odeK l oud 192.168.1.0 192.168.2.2 255.255.255.0 UG 0 0 0 eth0
??

A eth0 192.168.1.0 eth0 B eth1


192.168.2.0
eth0 C

192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5

ping 192.168.2.5
Connect: Network is unreachable

ip route add 192.168.2.0/24 via 192.168.1.6 ip route add 192.168.1.0/24 via 192.168.2.6

ping 192.168.2.5
© Copyright K odeK l oud
A eth0 192.168.1.0 eth0 B eth1
192.168.2.0
eth0 C

192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5

cat /proc/sys/net/ipv4/ip_forward
0

/etc/sysctl.conf
.6 echo 1 > /proc/sys/net/ipv4/ip_forward …
net.ipv4.ip_forward = 1
1 …
ping 192.168.2.5
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
© Copyright KodeKloud
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Take Aways
ip link

ip addr

ip addr add 192.168.1.10/24 dev eth0

ip route route

ip route add 192.168.1.0/24 via 192.168.2.1

cat /proc/sys/net/ipv4/ip_forward
1

© Copyright KodeKloud
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

Introduction
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
About Java

• Free Version Date


13 2019
• Open-source 12 2019
• Huge Community 11 2018
10 2018
9 2017
8 2014
7 2011
6 2006
5 2004

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Install Java

wget https://download.java.net....
openjdk-13.0.2_linux-x64_bin.tar.gz

tar –xvf openjdk-13.0.2_linux-x64_bin.tar.gz


/opt/jdk-13/bin/java -version Version Name
13 13
jdk-13.0.2/bin/java -version 12 12
openjdk version "13.0.2" 2020-01-14 11 11
OpenJDK Runtime Environment (build 13.0.2+8) 10 10
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode,
sharing) 9 9
8 1.8
java -version 7 1.7
openjdk version "1.8.0_242" 6 1.6
OpenJDK Runtime Environment (build 1.8.0_242-b08) 5 1.5
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://jdk.java.net/13/
Java Development Kit (JDK)

Develop Build Run

jdb javac JRE

javadoc jar (Java Runtime Environment)

java

ls jdk-13.0.2/bin
jaotc javadoc jdeprscan jinfo jps jstatd rmiregistry
jar javap jdeps jjs jrunscript keytool serialver
jarsigner jcmd jfr jlink jshell pack200 unpack200
java jconsole jhsdb jmap jstack rmic
javac
© Copyright jdb
KodeKloud jimage. jmod jstat rmid Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Before v9

Java Development Kit (JDK)


JRE
Develop Build Run
(Java Runtime Environment)
jdb javac
javadoc jar
java

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
After v9

Java Development Kit (JDK)


Develop Build Run

jdb javac JRE


javadoc jar
(Java Runtime Environment)
java

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

Build
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Compile
MyClass.java

1. Develop Source Code public class MyClass {


public static void main(String[] args) {
System.out.println("Hello World");
}
}

2. Compile javac MyClass.java


MyClass.class

3. Run java MyClass


Hello World

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Compile
MyClass.java Machine Code
public class MyClass { 01101000 10111100 10000001
public static void main(String[] args) { 01100100 01011100 00010111
System.out.println("Hello World"); 00001010 00001110 11111010
}
10110001 01101000 10111100
} Compiler
10000001 01100100 01011100
00010111 00001010 00001110
11111010 10110001 10110001

Human Readable Machine Readable


Source Code Machine Code

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Java Virtual Machine

MyClass.class Machine Code


MyClass.java
public class MyClass {
0: iconst_2 01101000 10111100 10000001
public static void main(String[] args) { 1: istore_1 01100100 01011100 00010111
System.out.println("Hello World");
}
2: iload_1 00001010 00001110 11111010
} 3: sipush 1000 10110001 01101000 10111100
Compiler 6: if_icmpge 44 10000001 01100100 01011100
9: iconst_2 00010111 00001010 00001110
10: istore_2 11111010 10110001 10110001
11: iload_2
12: iload_1 JVM
13: if_icmpge 31

Human Readable Intermediary Machine Readable


Source Code Byte Code Machine Code

javac MyClass.java java MyClass


© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
MyClass.class Hello World
Package
MyClass.class

Dependency 1 Service1.class

Dependency 2 Service2.class
Dependency 3
Utility.class

Tools.class
Java Archive
(JAR)

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Package
META-INF/MANIFEST.MF
MyClass.class

Dependency 1 Service1.class Manifest-Version: 1.0


Created-By: 1.8.0_242 (Private Build)
Dependency 2 Service2.class Main-Class: MyClass

Dependency 3
Utility.class

Tools.class
Image 1
Java Archive Web Archive
Image 2 HTML 1 (JAR) (WAR)
HTML 2

jar cf MyApp.jar MyClass.class Service1.class Service2.class ...


MyApp.jar

java -jar MyApp.jar


© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Hello World
Document

javadoc –d doc MyClass.java

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Build Process

Develop Compile Package Document

javac MyClass.java

jar cf MyClass.jar ..

javadoc MyClass.java
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Build Process

© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Build Tools

• Maven # Build Steps


• Gradle
• ANT 1.Compile

2.Package

3.Document

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
ant compile jar
ANT
BUILD SUCCESSFUL build.xml
Total time: 2 seconds
<?xml version="1.0"?>
<project name="Ant" default="main" basedir=".">
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile">
javac MyClass.java <javac srcdir="/app/src" destdir="/app/build">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="/app/src" destdir="/app/docs">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="/app/src">
javadoc MyClass.java <include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar basedir="/app/build" destfile="/app/dist/MyClass.jar" >
<manifest>
jar cf MyClass.jar .. <attribute name="Main-Class" value="MyClass" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
© Copyright KodeKloud </target>
Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg

</project>
Maven

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://github.com/shopizer-ecommerce/shopizer
Gradle

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://github.com/arun-gupta/docker-java-sample
Summary

• Java
• Java Runtime Environment
• Java Development Kit
• Compiling a Java application
• Packaging a given application to JARs
• What are Build Tools?

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
JavaScript

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://enonic.com/blog/websites-past-and-present
NodeJS

• Free Node.js 13.x


• Open source
• Cross Platform Compatible Node.js 12.x
Node.js 11.x
Node.js 10.x
Node.js 9.x
Node.js 8.x
Node.js 7.x
Node.js 6.x
Node.js 5.x
Node.js 4.x
Node.js 0.12.x
© Copyright KodeKloud Node.js 0.10.x
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Install NodeJS

curl -sL https://rpm.nodesource.com/setup_13.x | bash -

yum install nodejs


© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
NodeJS Commands
node -v
V13.10.1

node add.js add.js


Addition : 15 // Returns addition of two numbers
let add = function (a, b) {
return a+b;
};

const a = 10, b = 5;

console.log("Addition : "+ add(a,b));

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Node Package Manager (NPM)

• Files
• Web Servers
• Databases
• Security
• Many More

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://www.npmjs.com/
NPM Commands
npm -v
6.13.7

npm search file


NAME | DESCRIPTION | AUTHOR | DATE
file | Higher level path… | =aconbere | 2014-02-21
File | HTML5 FileAPI… | =coolaj86 =narf | 2014-10-24
dotenv | Loads environment… | =~jcblw… | 2019-10-16
fs-extra | fs-extra contains… | =jprichardson… | 2019-06-28
file-loader | A file loader… | =d3viant0ne… | 2020-02-19

npm install file node_modules


+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.072s file
found 0 vulnerabilities LICENSE
README.md
package.json
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
lib
package.json
NPM Commands
{
"author": {
"name": "Anders Conbere",
"email": "[email protected]"
},
"bundleDependencies": false,
"devDependencies": {
"mocha": "1.9.x"
},
"directories": {
"lib": "lib"
},
"homepage": "https://github.com/aconbere/node-file-utils#readme",
"license": "MIT",
"main": "./lib/file",
"name": "file",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/aconbere/node-file-utils.git" node_modules
},
"tags": [
"file",
file
"path", LICENSE
"fs",
"walk"
], README.md
"version": "0.2.2"
} package.json
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
lib
NPM Commands
npm install file
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.072s
found 0 vulnerabilities

app.js my_application
var file = require("file");
node_modules
file.mkdirs("/tmp/dir1") file
LICENSE
README.md
node -e "console.log(module.paths)"
package.json
[ '/app/node_modules', '/node_modules' ]
lib
npm install file -g app.js
© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Common Modules

Built-In Modules External Modules


fs To handle filesystem express Fast, unopinionated, minimalist web
http To host an HTTP server framework
os To work with the Operating System react To create user interfaces
events To handle events debug To debug applications
tls To implement TLS and SSL async To work with asynchronous JS
url To Parse URL Strings lodash To work with arrays, objects, strings etc

ls /usr/lib/node_modules/npm/node_modules/ ls /usr/lib/node_modules/

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
package.json
Application Dependencies
{
"name": "example-contentful-theExampleApp-js",
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "^1.18.2",
"contentful": "^6.0.0",
"cookie-parser": "~1.4.3",
"dotenv": "^5.0.0",
"execa": "^0.9.0",
"express": "^4.16.2",
"helmet": "^3.11.0",
"lodash": "^4.17.5",
"marked": "^0.3.16",
"morgan": "^1.9.1",
"pug": "~2.0.0-beta6"
}
}
© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python

• Free
• Open source
• Cross Platform Compatible

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Download

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
https://www.python.org/downloads/
Versions

• Python2 – (2000 – 2010)


• Python3 – (2008 to Present)

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Install
yum install python2 yum install python36

python2 python3
Python 2.7.16 (default, Nov 17 2019, 00:07:27) Python 3.6.8 (default, Nov 21 2019, 19:31:34)
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux2 [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" Type "help", "copyright", "credits" or "license"
for more information. for more information.
>>> exit() >>> exit()

python2 -V python3 -V
Python 2.7.16 Python 3.6.8

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Commands

python2 main.py main.py

Hello World
def print_message():
print("Hello World")

if __name__ == '__main__':
print_message()

© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
just enough

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Package Manager (pip)
python2 -V python3 -V
Python 2.7.16 Python 3.6.8

pip2 -V pip3 -V
pip 9.0.3 from /usr/lib/python2.7/site-packages pip 9.0.3 from /usr/lib/python3.6/site-packages
(python 2.7) (python 3.6)

pip -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)

pip install flask

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Python Package Manager (pip)
pip install flask

usr
lib
python2.7
site-packages
Python3.6
site-packages
lib64
python2.7
site-packages
Flask-1.1.1.dist-info
python3.6
© Copyright K odeK l oud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

site-packages
Python Package Manager (pip)
pip install flask

pip show flask


Name: Flask usr
Version: 1.1.1 main.py
Summary: A simple framework for building complex lib
web applications.
from flask import Flask, request
Home-page: https://palletsprojects.com/p/flask/ python2.7
Author: Armin Ronacher app = Flask(__name__)
site-packages
Author-email: [email protected]
License: BSD-3-Clause Python3.6
Location: /usr/lib64/python2.7/site-packages @app.route('/')
Requires: Werkzeug, click, Jinja2, itsdangerous def hello(): site-packages
return 'Hello,
lib64 World'
python2 -c "import sys; print(sys.path)"
python2.7
'/usr/lib/python27.zip', '/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2', site-packages
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old', Flask-1.1.1.dist-info
'/usr/lib64/python2.7/lib-dynload', python3.6
© Copyright KodeKloud
'/usr/lib64/python2.7/site-packages', Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

'/usr/lib/python2.7/site-packages' site-packages
Requirements
requirements.txt
pip install flask
Flask
Flask==0.10.1
pip install jinja2
Jinja2
Jinja2==2.7.3
pip install markupsafe
MarkupSafe
MarkupSafe==0.23

pip install Werkzeug Werkzeug


Werkzeug==0.9.6

pip install requests requests


requests==2.3.0

pip install gunicorn gunicorn


gunicorn==18.0

pip install flask jinja2 markupsafe pip install –r requirements.txt

© Copyright KodeKloud Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Upgrade/Uninstall Package

pip install flask --upgrade


Installing collected packages: click, flask
Attempting uninstall: flask
Found existing installation: Flask 0.10.1
Uninstalling Flask-0.10.1:
Successfully uninstalled Flask-0.10.1
Successfully installed click-7.1.1 flask-1.1.1

pip uninstall flask


Found existing installation: Flask 1.1.1
Uninstalling Flask-1.1.1:
Would remove:
/home/vagrant/.local/bin/flask
/home/vagrant/.local/lib/python3.5/site-
packages/Flask-1.1.1.dist-info/*
/home/vagrant/.local/lib/python3.5/site-
packages/flask/*
Proceed (y/n)? y
© Copyright Successfully
K odeK l oud uninstalled Flask-1.1.1 Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg
Other Package Managers

• easy_install easy_install install app

</>

app.py setuptools app.egg

• wheels pip install app.whl

</>

app.py setuptools app.whl


© Copyright KodeKloud Check out our full course on DevOps Pre-R equisites: https://kode.wiki/43z8frg
Check out our full course on DevOps Pre-Requisites: https://kode.wiki/43z8frg

© Copyright KodeKloud
Git
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout

Explore nature
in Canada.
See more

👩🏼‍💻
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local

Home Contact Abbout Home Contact Abbout

Explore nature Explore nature


in Canada. in Canada.
See more See more

👩🏼‍💻
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local

Home Contact Abbout Home Contact About

Explore nature
Explore nature in Canada.
Visit Canada’s lakes and
in Canada. mountains.

See more See more

👩🏼‍💻
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com local

Home Contact Abbout Home Contact About

Explore nature
Explore nature in Canada.
Visit Canada’s lakes and
in Canada. mountains.

See more See more

🤷🏼‍
🤦🏼‍
👩🏼‍💻
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Git
© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Content tracker

Distributed Version Control System

Git
© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact About

Explore nature
in Canada. New state of your website with
Visit Canada’s lakes and
mountains.
the local changes
See more

Home Contact Abbout

Explore nature
Hosted state of your website
in Canada.
See more

© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Fixed button CSS
@ma 🙋🏽‍ 12.23AM
x

Changed background image @sara


🙋🏼‍ 11.15AM

Added sub title @tim


💁🏼‍ 11.05AM

@ma 🙋🏽‍
Fixed buttons in navigation x 10.45AM

Added front page @sara


🙋🏼‍ 10.24AM

© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout

Explore nature
in Canada.
Visit Canada’s lakes and
mountains.

See more
Change background

Home Contact Abbout

Explore nature
in Canada.
Added front page
See more

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout

Explore nature
in Canada.
Visit Canada’s lakes and
mountains.

See more
Change background

Home Contact Abbout

Explore nature
in Canada.
Added front page
See more

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Home Contact Abbout

Explore nature
in Canada.
Visit Canada’s lakes and
mountains.

See more
Change background

Home Contact Abbout

Explore nature
in Canada.
Added front page
See more

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com

Home Contact About

Explore nature
in Canada.
See more

Home Contact Abbout Home Contact About

Explore nature
in Canada.
Visit Canada’s lakes and
Explore nature
in Canada.
mountains.

See more
Change background Fixed button typo See more

Home Contact Abbout

Explore nature
in Canada.
Added front page
See more

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
www.mywebsite.com

Home Contact About

Explore nature
in Canada.
See more

Home Contact Abbout Home Contact About

Explore nature
in Canada.
Visit Canada’s lakes and
Explore nature
in Canada.
mountains.

See more
Change background Fixed button typo See more

Home Contact Abbout

Explore nature
in Canada.
Added front page
See more

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

Local Repository

<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>

© Copyright K odeK l oud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
Remote Repository

<html>
<body>
<h1>My Website!</h1>
</body>
</html>

Local Repository
Local Repository
👱🏾‍
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>

© Copyright KodeKloud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

<html>
<body>
<h1>My Website!</h1>
</body>
</html>

Local Repository
Local Repository
👱🏾‍
<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

<html>
<body>
<h1>My Website!</h1>
</body>
</html>

Local Repository
Local Repository
👱🏾‍
<html>
<body>
👩🏽 <html>
<body>
<h1>My Website!</h1>
<h1>My Website!</h1>
<p>This is some more text!</p>
</body>
</body>
</html>
</html>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

<html>
<body>
<h1>My Website!</h1>
</body>
</html>

Local Repository
Local Repository
👱🏾‍
<html>
<body>
👩🏽 <html>
<html>
<body>
<body>
<h1>My
<h1>MyWebsite!</h1>
Website!</h1>
<h1>My Website!</h1>
<p>This
<p>Thisisissome
somemore
moretext!</p>
text!</p>
</body>
</body>
</body>
</html>
</html>
</html>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

<html>
<html>
<body>
<body>
<h1>My Website!</h1>
<h1>My Website!</h1>
<p>This is some more text!</p>
</body>
</body>
</html>
</html>

Local Repository
Local Repository
👱🏾‍
<html>
<body>
👩🏽 <html>
<html>
<body>
<body>
<h1>My
<h1>MyWebsite!</h1>
Website!</h1>
<h1>My Website!</h1>
<p>This
<p>Thisisissome
somemore
moretext!</p>
text!</p>
</body>
</body>
</body>
</html>
</html>
</html>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository

Working Area Staging Area Committed Files

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Fixed button CSS
@ma 🙋🏽‍ commit
x

Changed background image @sara


🙋🏼‍ commit

Added sub title @tim


💁🏼‍ commit

@ma 🙋🏽‍ commit


Fixed buttons in navigation x

Added front page @sara


🙋🏼‍ commit

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository

Working Area Staging Area Committed Files

story2.txt

story1.txt

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Initialize Git Repo
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git init
Initialized empty Git repository in
/Users/lydiahallie/Desktop/myproject/.git/

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ ls -a
. .. .git

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ touch story1.txt
$ echo "This is a beautiful story" >> story1.txt

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git status
On branch master

No commits yet

Untracked files:
story1.txt

nothing added to commit but untracked files present

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

Working Area Staging Area Committed Files

story1.txt

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git add story1.txt

Working Area Staging Area Committed Files

story1.txt

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git commit -m "Added first story"

Working Area Staging Area Committed Files

story1.txt

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Added first story
@ 🙋🏼‍
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Git log
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git log
commit 67c833e3…ecb7df62f (HEAD -> master)

Author: John Doe <john@doe>

Date: Sun Jun 14 14:45:07 2020 -0700

Added first story

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git log —-oneline


67c833e (HEAD -> master) Added first story

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Branches
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Merging
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Initializing a remote repo
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Connection
String

https://.../.../[name].git

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git remote add origin https://.../.../[name].git

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Local Repository

Working Area Staging Area Committed Files

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
https://.../.../[name].git
Remote Repository

Local Repository

Working Area Staging Area Committed Files

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git remote -v
origin https://.../.../[name].git (fetch)
origin https://.../.../[name].git (push)

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Pushing
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Remote Repository

Local Repository

<html>
<body>
👩🏽
<h1>My Website!</h1>
</body>
</html>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git push origin master

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Added fifth story
@ 🙋🏼‍
me

Added fourth story


@ 🙋🏼‍
me

Added third story


@ 🙋🏼‍
me

Added second story


@ 🙋🏼‍ local remote
me

Added first story


@ 🙋🏼‍
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Cloning
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git clone <ssh link>

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git clone [email protected]:….…git


Cloning into 'remote-repo'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 2948 (delta 28), reused 18 (delta 6)
Receiving objects: 100% (2948/2948), 1.93 MiB | 2.53 MiB/s, done.
Resolving deltas: 100% (1526/1526), done.

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ cd remote-repo
$ git log
commit 67c833e3…ecb7df62f (HEAD -> origin/master)

Author: John Doe <john@doe>

Date: Sun Jun 14 14:45:07 2020 -0700

Added first story

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Pull Request
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
sarah max
@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻
🧔🏻

Added first story


@ 🙋🏼‍ master origin/master
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git push origin sarah

origin/sarah sarah max


@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻

Added first story


@ 🙋🏼‍ master origin/master
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Fetching and Pulling
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git fetch origin master

origin/sarah sarah max


@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻

Added first story


@ 🙋🏼‍ master origin/master
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git merge origin/master

origin/master

origin/sarah sarah max


@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻

Added first story


@ 🙋🏼‍ master
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git pull origin master

origin/sarah sarah max


@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻

Added first story


@ 🙋🏼‍ master origin/master
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Merge Conflicts
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Merge sarah into master @sarah 👩🏽‍💻
sarah max master
@ma
Added second story @sarah 👩🏽‍💻 Added third story
x 🧔🏻

Added first story


@ 🙋🏼‍
me

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md fourth_story.md

## Fourth Story ## Fourth Story

This is Sarah’s version This is Max’s version


of the fourth story! of the fourth story!

Some extra stuff Sarah


added

sarah max
@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

master

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
sarah max
@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

master

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
master sarah max
@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md fourth_story.md

## Fourth Story ## Fourth Story

This is Sarah’s version This is Max’s version


of the fourth story! of the fourth story!

master sarah max


@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md

## Fourth Story

<<<<<<<< HEAD
This is Sarah’s version
=======
This is Max’s version
>>>>>>> max
of the fourth story!

Some extra stuff Sarah


added

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
fourth_story.md

## Fourth Story

<<<<<<<< HEAD
This is Sarah’s version
=======
This is Max’s version
>>>>>>> max
of the fourth story!

Some extra stuff Sarah


added

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git add fourth_story.txt


$ git merge

master sarah max


@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
bash

$ git add fourth_story.txt


$ git merge

@ma
Merge max into master
x 🧔🏻
master sarah max
@ma
Started fourth story @sarah 👩🏽‍💻 Started fourth story
x 🧔🏻

© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


Fork
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
© Copyright K odeK l oud Check out our full course on GI T for Beginners: https://kode.wiki/3MUhuve
Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve

© Copyright K odeK l oud


What is Jenkins
Jenkins is one of the most popular automation
tool used worldwide for continuous integration
and continuous delivery.
Jenkins is a free and open-source automation
server that enables developers to build, integrate,
and test code automatically as soon as it is
committed to the source repository.

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Why Jenkins?
Challenges

When working on a project with different teams,


developers often face issues with different teams using
different CI tools, version management, and other tools.
Slower Releases
Setting up a CI/CD toolchain for each new project will lead
to certain challenges like:

• Slower Releases
• Manual Builds Manual Builds
• Non-repeatable processes
• No Automations

Non-repeatable No automations
processes

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Why Jenkins?
Solution

Jenkins is the solution to those challenges.


It provides:
Automated builds Automated Tests
• Automated builds
• Automated Tests
• Automated CI/CD pipelines
• Automated deployments CI CD

• Ability to install Jenkins locally Automated CI/CD Automated


• Jenkins support and Plugins pipelines deployments

Ability to install Jenkins support


Jenkins locally and Plugins
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Why Jenkins?

Open-source 1000+ plugins Free Paid, Enterprise

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Free!

Jenkins is free and you don’t have to pay for anything.


Jenkins can be hosted on a Virtual Machine, a container. Or
even locally for development purposes.

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Plugins

Jenkins is well tested and provide several integrations with


1800+ plugins to support build, deployment and automation
for the project

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Enterprise Options

Support

Managed
Service

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Continuous Integration
Continuous Integration is a process in which the code is
merged from multiple contributors and added to a single
repository.
In simple words, CI is a process to take the code package it
and send it to the CD for further processing.

Continuous Deployment
Continuous Deployment is an automated process in which the
code is taken from the repository and deployed to the system.

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Continuous Integration and
Continuous Delivery/Deployment (CICD)

CI/CD in simple words is a process to take a code, package it up and


deploy it to a system that can be serverless, a VM, or a container.
CI/CD can be broken down into 3 steps:

• CI – Continuous Integration
• CD – Continuous Delivery
• CD – Continuous Deployment

CI CD CD

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
The Key Pieces of CI

Key Processes of Continuous Integration


• Package up the code
• Test the code (run unit tests, integration tests, etc)
• Run security checks against the code

>_ Tests Security Checks

Unit tests

Integration tests

© Copyright K odeK l oud


Continuous Integration (CI)

Think of the Continuous Integration process like a gift you're wrapping

• The gift comes in pieces


• You put the gift together (maybe a toy chest/box)
• The gift gets wrapped in wrapping paper
• You put it in the car and deliver it to the person.

© Copyright K odeK l oud


Continuous Integration (CI)

© Copyright K odeK l oud


Continuous Deployment vs
Continuous Delivery

The basic difference between Continuous Delivery and Continuous


Deployment is that in Continuous Delivery to deploy the code after the CI
process you have to manually trigger it via some button to deploy on the
system whereas in Continuous Deployment this process is automatic.

CD CD

Continuous Delivery Continuous Deployment

CI CI

© Copyright K odeK l oud


Key Pieces of CD

Key Pieces of CD:


• Ensure you're authenticated to the system or wherever you're deploying
• Ensure that the code that's being deployed is working as expected once it's deployed

Authenticate >_ Tests

CD process

System

CD

© Copyright K odeK l oud


Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Installing Jenkins

Ubuntu 20.04

https://www.jenkins.io/doc/book/installing/linux/
© Copyright K odeK l oud
Install Jenkins on Ubuntu
Step 1: Install Java on Ubuntu Step 3: Once the key is added with no
errors, append the Debian package
$ sudo apt update repository address
$ sudo apt sudo apt install openjdk-8-jdk
$ sudo sh -c 'echo deb
Alternatively, install version 11: http://pkg.jenkins.io/debian-stable
$ sudo apt install openjdk-11-jdk binary/ >
/etc/apt/sources.list.d/jenkins.list’
Confirm the download by pressing Y and
Enter Step 4: Run update to use new repository

Step 2: Add the repository key to the $ sudo apt update


system:
Step 5: Install Jenkins
$ sudo apt wget -q -O -
https://pkg.jenkins.io/debian- $ sudo apt install jenkins
stable/jenkins.io.key | sudo apt-key add -
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Start Jenkins on Ubuntu
After successful installation let us start Jenkins

$ sudo systemctl start jenkins

The above command will not display any output

To check the running status of Jenkins use the below command


which should show active status on run

$ sudo systemctl status jenkins

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Jenkins Plugins
Plugins are used in Jenkins to enhance Jenkins functionality and cater to user-specific needs.
Just like how Gmail, Facebook and LinkedIn help you connect your one service to another,
plugins also work the same way and allow us to connect one service to other services and
work with other products.

Login with Google

Login with Facebook

Login with LinkedIn


User Website

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Plugins

For example, you want to connect to Azure from Jenkins you would need to download Azure Plugin which
will allow you to connect to Azure at a programmatic level.
Similarly, we can have other integrations with AWS, GitHub, etc using plugins.

Azure Plugin

AWS Plugin
Jenkins

Github Actions Plugin

© Copyright K odeK l oud


Install Plugins
To install a new plugin in Jenkins
1) Go to Manage Jenkins -> Manager Plugins
2) Click Available and search for the desired plugin.
3) Select the desired plugin and Install.
Note: Few plugins may need a restart

To restart Jenkins
$ sudo systemctl restart jenkins

OR

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Update Plugins
To update any existing plugin in Jenkins
1) Go to Manage Jenkins -> Manager Plugins
2) Click Updates and search for the desired plugin.
3) Select the desired plugin and Install.
Note: Few plugins may need a restart

To restart Jenkins
$ sudo systemctl restart jenkins

OR

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Delete Plugins
To delete any plugin in Jenkins
1) Go to Manage Jenkins -> Manager Plugins
2) Go to Installed and search for the desired plugin.
3) Click on uninstall button for the plugin you want to delete.
Click yes to proceed with the deletion.

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Jenkins Visuals

Visuals Jenkins Build User Navigate


Menu account

© Copyright K odeK l oud


Jenkins Jobs
Different types of jobs that can be created in Jenkins:
1) Freestyle project
This is a central feature of Jenkins. It will build the project, combine SCM with the build system. It can
also be used for things other than building applications.

2) Pipeline
This is used to create a pipeline

3) Multi-configuration project
This is great if you need a large number of Jenkins configurations if you need multiple environments
like Dev/ UAT.

4) Folder
This creates containers and stores nested items. It is useful in grouping, creating a namespace, etc.

5) Organisation folder
Creates a multibranch project for all different subfolders that are available.

6) Multibranch Pipeline
It sets up pipeline projects for different repositories.
© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Administering Jenkins

Backup Restore Monitor

Scale Manage
© Copyright K odeK l oud
Backup and Restore

Full

Snapshots
Backup

© Copyright K odeK l oud


Which Files To Backup?

$JENKINS_HOME

Configuration files jobs


(config.xml)

© Copyright K odeK l oud


Backup Jenkins
It is crucial to have adequate backups of your Jenkins instance. Backups are
used to recover from accidental configuration changes. Recovering a file that
has been mistakenly erased or has been corrupted. Or just to recover a
previous setup.

There are two ways we can backup Jenkins:

1) Using Plugins
2) Using custom shell script

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Backup Jenkins
To backup Jenkins using a plugin, you will first need to install a backup plugin.
Some of the most commonly used plugins are ThinBackup, Periodic Backup,
Google cloud Backup.

For backing up using any of these plugins there are a few general steps that
must be followed:
1) Creating a backup directory with read and write access
2) Selecting files that need backup

Backing up using shell script


Please check out these popular repositories for your reference:
1) repository: https://github.com/sue445/jenkins-backup-script
2) gist: https://gist.github.com/abayer/527063a4519f205efc74

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


Jenkinsfile
Jenkinsfile is a text file that contains definitions. This could be
templates or instructions. It tells pipelines what they should be
doing and what services and plugins they should be interacting
with.

Components of Jenkinsfile:

1) Pipeline – The task you are trying to accomplish


2) Build Agent –The place where you run your pipeline
3) Stages – Staging/Production/UAT
4) Steps –Work done in the pipeline

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
What Is A Jenkinsfile?

Instructions

Templates

Jenkinsfile

© Copyright K odeK l oud


What Is A Jenkinsfile?

Instructions

Templates

Jenkinsfile

© Copyright K odeK l oud


Components of Jenkinsfile

© Copyright K odeK l oud Check out our full course onJ enkins: https://kode.wiki/3oQvNJ n
Dev Staging Prod

Jenkinsfile Jenkinsfile Jenkinsfile

Dev Staging Prod

Jenkinsfile

© Copyright K odeK l oud


Multi-Stage Pipelines

Dev Staging Prod

Jenkinsfile Jenkinsfile Jenkinsfile

Dev Staging Prod

Jenkinsfile
© Copyright K odeK l oud
Check out our full course on Jenkins: https://kode.wiki/3oQvNJn

© Copyright K odeK l oud


docker
for beginners

© Copyright K odeK l oud Check


Check
outout
ourour
fullfull
course
course
onon
Docker
Docker
forfor
thethe
Absolute
Absolute
Beginners:
Beginners:
https://kode.wiki/3N9p
https://kode.wiki/3N9p
J JUuUu
Objectives
➢ What are Containers?
➢ What is Docker?
➢ Why do you need it?
➢ What can it do?

➢ Run Docker Containers


➢ Create a Docker Image
➢ Networks in Docker
➢ Docker Compose

➢ Docker Concepts in Depth

➢ Docker for Windows/Mac

➢ Docker Swarm
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
➢ Docker vs Kubernetes
docker
overview

© Copyright K odeK l oud Check


Check
outout
ourour
fullfull
course
course
onon
Docker
Docker
forfor
thethe
Absolute
Absolute
Beginners:
Beginners:
https://kode.wiki/3N9p
https://kode.wiki/3N9p
J JUuUu
Why do you need docker?
Web Server Database Messaging Orchestration

• Compatibility/Dependency
• Long setup time
• Different Dev/Test/Prod
environments
The Matrix from Hell !!

Libraries Dependencies

OS

Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What can it do?
Container Container Container Container

• Containerize Web Server Database Messaging Orchestration

Applications
• Run each service with its
own dependencies in
separate containers

Libs Deps Libs Deps Libs Deps Libs Deps

Docker
?

OS

Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What are containers?

Processes Processes Processes Processes


Network Network Network Network
Mounts Mounts Mounts Mounts

Docker

OS Kernel

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Operating System

OS

Software Software Software Software

OS Kernel

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Sharing the kernel

Software Software Software Software

Docker

OS - Ubuntu

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Containers vs Virtual Machines


GB ✓
✓ MB
✓ ✓
Utilization Size Boot up Utilization Size Boot up

Virtual Machine Virtual Machine


Container Container
Application Application
Application Application
Libs Deps Libs Deps
OS OS Libs Deps Libs Deps

Docker
Hypervisor
OS

Hardware Infrastructure Hardware Infrastructure


© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Containers & Virtual Machines
Virtual Machine Virtual Machine
Container Container Container Container

Application Application Application Application


Libs Deps Libs Deps Libs Deps Libs Deps

Docker Docker
OS OS

Hypervisor
OS

Hardware Infrastructure
Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
How is it done? Public Docker registry - dockerhub

docker run ansible

docker run mongodb

docker run redis

docker run nodejs

docker run nodejs

docker run nodejs

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Container vs image

Docker Container #1

Docker Image

Package Docker Container #2


Template
Plan

© Copyright K odeK l oud


Docker Container #3
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Docker in DevOps

App.war

Docker Image
Guide
DockerFile

Developer DevOps Operations

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

Getting Started

© Copyright K odeK l oud Check


Check
outout
ourour
fullfull
course
course
onon
Docker
Docker
forfor
thethe
Absolute
Absolute
Beginners:
Beginners:
https://kode.wiki/3N9p
https://kode.wiki/3N9p
J JUuUu
Docker Editions

Community Edition Enterprise Edition

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition

Linux MAC Windows Cloud

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition

MAC Windows Cloud


Linux

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Community Edition

Linux Cloud
MAC Windows

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
d e m o

Install Docker

© Copyright K odeK l oud Check


Check
outout
ourour
fullfull
course
course
onon
Docker
Docker
forfor
thethe
Absolute
Absolute
Beginners:
Beginners:
https://kode.wiki/3N9p
https://kode.wiki/3N9p
J JUuUu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


docker
commands

© Copyright K odeK l oud Check


Check
outout
ourour
fullfull
course
course
onon
Docker
Docker
forfor
thethe
Absolute
Absolute
Beginners:
Beginners:
https://kode.wiki/3N9p
https://kode.wiki/3N9p
J JUuUu
Run – start a container
docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
fc7181108d40: Already exists
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
ps – list containers
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
STOP – stop a container
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet

docker stop silly_sammet


silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Exited (0) 3 seconds ago silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Rm – Remove a container
docker rm silly_sammet
silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
images – List images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f68d6e55e065 4 days ago 109MB
redis latest 4760dc956b2d 15 months ago 107MB
ubuntu latest f975c5035748 16 months ago 112MB
alpine latest 3fd9065eaf02 18 months ago 4.14MB

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
rmi – Remove images
docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Deleted: sha256:f68d6e55e06520f152403e6d96d0de5c9790a89b4cfc99f4626f68146fa1dbdc
Deleted: sha256:1b0c768769e2bb66e74a205317ba531473781a78b77feef8ea6fd7be7f4044e1
Deleted: sha256:34138fb60020a180e512485fb96fd42e286fb0d86cf1fa2506b11ff6b945b03f
Deleted: sha256:cf5b3c6798f77b1f78bf4e297b27cfa5b6caa982f04caeb5de7d13c255fd7a1e

! Delete all dependent containers to remove image

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Pull – download an image
docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
fc7181108d40: Already exists
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest

docker pull nginx


Using default tag: latest
latest: Pulling from library/nginx
fc7181108d40: Pull complete
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS


45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS


45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Append a command
docker run ubuntu

docker run ubuntu sleep 5

5
4
3
2
1

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Exec – execute a command
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
538d037f94a7 ubuntu "sleep 100“ 6 seconds ago Up 4 seconds distracted_mcclintock

docker exec distracted_mcclintock cat /etc/hosts


127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.2 538d037f94a7

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – attach and detach
docker run kodekloud/simple-webapp
This is a sample web application that displays a colored background.
* Serving Flask app "app" (lazy loading)
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

docker run –d kodekloud/simple-webapp


a043d40f85fefa414254e4775f9336ea59e19e5cf597af5c554e0a35a1631118

docker attach a043d

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


docker

run

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – tag
docker run ubuntu

docker run Ubuntu:17.04 TAG

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – attach and detach
docker run mmumshad/simple-webapp

docker run –d mmumshad/simple-webapp

docker attach sad_ramanujan

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
RUN - STDIN

docker run mmumshad/simple-prompt-docker

docker run –i mmumshad/simple-prompt-docker

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Run – PORT mapping
docker run mmumshad/simple-webapp
http://192.168.1.5:80

80 8000 8001

IP: 192.168.1.5

http://172.17.0.2:5000 Internal IP
5000 5000 5000

IP: 172.17.0.2 IP: 172.17.0.3 IP: 172.17.0.4


docker run –p 80:5000 mmumshad/simple-webapp 3
3 Web APP Web APP Web APP
0 Docker Container Docker Container Docker Container
docker run –p 8000:5000 mmumshad/simple-webapp 6
3 IP: 172.17.0.5 3 IP: 172.17.0.6 3 IP: 172.17.0.6
3 MySQL 3 MySQL 3 MySQL
docker run –p 8001:5000 mmumshad/simple-webapp 0 Docker 0 0
Docker Docker
6 Container 6 Container 6 Container
8
docker run –p 3306:3306 mysql 3
0
6
docker run –p 8306:3306 mysql Docker Host
docker run –p 8306:3306 mysql

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
RUN – Volume mapping
docker run mysql

docker stop mysql


docker rm mysql

Data
docker run –v /opt/datadir:/var/lib/mysql mysql /var/lib/mysql
/opt/datadir
MYSQL
Docker Container

Docker Host

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

images

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What am I containerizing?

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
How to create my own image?
Dockerfile

FROM Ubuntu 1. OS - Ubuntu


RUN apt-get update
RUN apt-get install python 2. Update apt repo

RUN pip install flask 3. Install dependencies using apt


RUN pip install flask-mysql

COPY . /opt/source-code
4. Install Python dependencies using pip

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run 5. Copy source code to /opt folder

6. Run the web server using “flask” command

docker build Dockerfile –t mmumshad/my-custom-app

docker push mmumshad/my-custom-app Docker


Registry
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Dockerfile
Dockerfile

INSTRUCTION ARGUMENT

Dockerfile
Start from a base OS or
FROM Ubuntu another image

RUN apt-get update


RUN apt-get install python
Install all dependencies
RUN pip install flask
RUN pip install flask-mysql

COPY . /opt/source-code Copy source code

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run Specify Entrypoint


© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Layered architecture
Dockerfile docker build Dockerfile –t mmumshad/my-custom-app

FROM Ubuntu Layer 1. Base Ubuntu Layer 120 MB

RUN apt-get update && apt-get –y install python


Layer 2. Changes in apt packages 306 MB
RUN pip install flask flask-mysql
Layer 3. Changes in pip packages 6.3 MB
COPY . /opt/source-code
Layer 4. Source code 229 B
ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
Layer 5. Update Entrypoint with “flask” command 0B

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Docker build output

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
failure
docker build Dockerfile –t mmumshad/my-custom-app

Layer 1. Base Ubuntu Layer

Layer 2. Changes in apt packages


Layer 3. Changes in pip packages

Layer 4. Source code


Layer 5. Update Entrypoint with “flask” command

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
What can you containerize?

Containerize Everything!!!

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


docker
environment
variables

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py

import os
from flask import Flask

app = Flask(__name__)


color = "red"

@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

python app.py
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py
import os
from flask import Flask

app = Flask(__name__)


color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Environment Variables
app.py
import os
from flask import Flask

app = Flask(__name__)


color = os.environ.get('APP_COLOR')
"red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

export APP_COLOR=blue; python app.py


© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
ENV Variables in Docker

app.py

import os
from flask import Flask

app = Flask(__name__)


os.environ.get('APP_COLOR')
color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

simple-webapp-color
docker run -e APP_COLOR=blue
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
ENV Variables in Docker
docker run -e APP_COLOR=blue simple-webapp-color

docker run -e APP_COLOR=green simple-webapp-color

docker run -e APP_COLOR=pink simple-webapp-color

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


docker

CMD
vs
ENT RYPOINT

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
??

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker run ubuntu [COMMAND]

docker run ubuntu sleep 5

5
4
3
2
1

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu

CMD sleep 5

CMD command param1 CMD sleep 5


CMD [“command”, “param1”] CMD [“sleep”, “5”] CMD [“sleep 5”]

docker build –t ubuntu-sleeper .


5
4
3
2
1
docker run ubuntu-sleeper

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu
docker run ubuntu-sleeper sleep 10

CMD sleep 5
Command at Startup: sleep 10

FROM Ubuntu
docker run ubuntu-sleeper 10
10
sleep
ENTRYPOINT [“sleep”]

Command at Startup:
docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.

Command at Startup:
© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
FROM Ubuntu docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.
ENTRYPOINT [“sleep”]

CMD [“5”]

Command at Startup:

docker run ubuntu-sleeper 10 10

Command at Startup:

sleep2.0
docker run --entrypoint sleep2.0 ubuntu-sleeper 10 10

© Copyright K odeK l oud Command at Startup: Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

engine

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Docker Engine
Docker Engine Laptop

Docker CLI

REST API

Docker Deamon docker –H=remote-docker-engine:2375

docker –H=10.123.2.1:2375 run nginx

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
containerization
Unix
Process ID
Timesharing

Network Namespace Mount

InterProcess

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Namespace - PID
Linux System
PID : 1

PID : 2

PID : 3
Child System (Container)
PID : 4

PID : 5 PID : 1

PID : 6 PID : 2

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
cgroups
Linux System

Docker Docker Docker


Container Container Container

CPU Memory

docker run --cpus=.5 ubuntu

docker run --memory=100m ubuntu

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

storage

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
File system
/var/lib/docker
aufs
containers
image
volumes

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Layered architecture
Dockerfile Dockerfile2
FROM Ubuntu FROM Ubuntu

RUN apt-get update && apt-get –y install python RUN apt-get update && apt-get –y install python

RUN pip install flask flask-mysql RUN pip install flask flask-mysql

COPY . /opt/source-code COPY app2.py /opt/source-code

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask ENTRYPOINT FLASK_APP=/opt/source-code/app2.py flask


run run

docker build Dockerfile –t mmumshad/my-custom-app docker build Dockerfile2 –t mmumshad/my-custom-app-2

Layer 1. Base Ubuntu Layer 120 MB Layer 1. Base Ubuntu Layer 0 MB

Layer 2. Changes in apt packages 306 MB Layer 2. Changes in apt packages 0 MB

Layer 3. Changes in pip packages 6.3 MB Layer 3. Changes in pip packages 0 MB

Layer 4. Source code 229 B Layer 4. Source code 229 B

Layer 5. Update Entrypoint


© Copyright K odeK l oud 0B Layer 5. Update Entrypoint 0 B J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
Layered architecture

Read Write
Container Layer
Layer 6. Container Layer

docker run mmumshad/my-custom-app

Read Only
Layer 5. Update Entrypoint with “flask” command
Layer 4. Source code

Image Layers Layer 3. Changes in pip packages


Layer 2. Changes in apt packages
Layer 1. Base Ubuntu Layer

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker build Dockerfile –t mmumshad/my-custom-app
COPY-ON-WRITE

Read Write
Container Layer

temp.txt

Read Only

Image Layers app.py

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
volumes docker run –v data_volume:/var/lib/mysql mysql

docker volume create data_volume docker run –v data_volume2:/var/lib/mysql mysql

/var/lib/docker docker run –v /data/mysql:/var/lib/mysql mysql

volumes docker run \


–-mount type=bind,source=/data/mysql,target=/var/lib/mysql mysql
data_volume

Read Write Read Write

/var/lib/mysql /var/lib/mysql

mysql-container layer mysql-container layer

data_volum
e mysql

/var/lib/docker/volumes /data

Read Only
mysql – image layer
© Copyright K odeK l oud Docker Host Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Storage drivers
• AUFS
• ZFS
• BTRFS
• Device Mapper
• Overlay
• Overlay2

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

networking

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Default networks
Bridge none host

docker run ubuntu docker run Ubuntu –-network=none docker run Ubuntu --network=host

5000 5000

Web Web Web Web


Container Container
Container Container
172.17.0.2 172.17.0.3
172.17.0.1
docker0
Web
Container
172.17.0.4 172.17.0.5

Web Web
Container Container

Docker Host Docker Host Docker Host


© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
User-defined networks

docker network create \


Web Web –-driver bridge \
Container Container
-–subnet 182.18.0.0/16
172.17.0.2 182.18.0.3
172.17.0.3 custom-isolated-network
172.17.0.1 182.18.0.1
docker0 docker0

172.17.0.4 172.17.0.5
182.18.0.2 docker network ls

Web Web
Container Container

Docker Host

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Network Inspect

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Embedded DNS

Host IP
mysql.connect( 172.17.0.3
mysql ) web mysql web 172.17.0.2
Container Container
172.17.0.2 172.17.0.3 mysql 172.17.0.3
docker0

DNS
Server

127.0.0.11

Docker Host

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


d o c k e r

registry

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image

docker run nginx

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image

image: nginx

Image/
Repository

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Image

image: nginx/nginx

User/ Image/
Account Repository

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
docker.io
Docker Hub

Image

image: docker.io/ nginx/nginx

Registry User/ Image/


Account Repository
gcr.io/ kubernetes-e2e-test-images/dnsutils

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Private Registry
docker login private-registry.io
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com to create one.
Username: registry-user
Password:
WARNING! Your password will be stored unencrypted in /home/vagrant/.docker/config.json.

Login Succeeded

docker run private-registry.io/apps/internal-app

© Copyright KodeKloud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9p
J Uu
Deploy Private Registry
docker run -d -p 5000:5000 --name registry registry:2

docker image tag my-image localhost:5000/my-image

docker push localhost:5000/my-image

docker pull localhost:5000/my-image

docker pull 192.168.56.100:5000/my-image

© Copyright K odeK l oud Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu
Check out our full course on Docker for the Absolute Beginners: https://kode.wiki/3N9pJUu

© Copyright K odeK l oud


for beginners
Who am I?

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Course Structure

Lecture Demos Quiz Lab Exercises

Tips & Q&A


Tricks
© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Who is this for?

Developers System Admins Managers

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
How to attend this course?

Lectures

Demos

Quizzes

Lab Exercises

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Labs

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Objectives
⮚Kubernetes Overview
⮚Containers – Docker
⮚Container Orchestration?
⮚Demo - Setup Kubernetes
⮚Kubernetes Concepts – PODs | ReplicaSets | Deployment | Services
⮚Networking in Kubernetes
⮚Kubernetes Management - Kubectl
⮚Kubernetes Definition Files - YAML
⮚Kubernetes on Cloud – AWS/GCP

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubernetes or K8s

Container + Orchestration

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Containers

mumshad mannambeth
Why do you need containers?
Web Server Database Messaging Orchestration
Compatibility/Dependency
Long setup time
Different Dev/Test/Prod
environments

The Matrix from Hell


!!
Libraries Dependencies

OS

Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
What can it do?
Containe Containe Containe Containe
Containerize Applications r r r
r
Web Server Database Messaging Orchestration
Run each service with its own
dependencies in separate containers

Libs Deps Libs Deps Libs Deps Libs Deps

Docker
?

OS

Hardware Infrastructure
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
What are containers?

Processe Processe Processe Processe


sNetwor sNetwor sNetwor sNetwor
k k k k
Mount Mount Mount Mount
s s s s
Docker

OS Kernel

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Operating system

OS

Software Software Software Software

OS Kernel

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Sharing the kernel

Software Software Software Software

Docker

OS - Ubuntu

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Containers vs Virtual Machines


GB ✔ ✔
✔ ✔
MB
✔ ✔
Utilizatio Size Boot Utilizatio Size Boot
n up n up
Virtual Virtual
Containe Containe
Machine Machine
Application Application r r
Application Application
Libs Deps Libs Deps
OS OS Libs Deps Libs Deps

Hypervisor Docker

OS OS

Hardware Infrastructure Hardware Infrastructure


Public Docker registry - dockerhub
How is it done?
docker run ansible

docker run mongodb

docker run redis

docker run nodejs

docker run nodejs

docker run nodejs

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container vs image

Docker Container #1

Docker
Image
Package
Docker Container #2
Templat
e
Plan

Docker Container #3
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container Advantage

App.wa
r

Docker Image
Guide
DockerFile

Developer Operations

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
More about containers

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container
Orchestration

mumshad mannambeth
Container Orchestration

Host Host Host Host

Orchestration

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Container orchestration
Orchestration

Web Web Web Web Web


Container Container Container Container Container

MySQL
Container

Docker Host Docker Host Docker Host Docker Host

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Orchestration Technologies

Docker Swarm

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Kubernetes Advantage

Orchestration

Web Web Web Web Web

Web Web Web Web

Backend Backend Backend Backend Backend

Kubernetes Kubernetes Kubernetes Kubernetes Kubernetes Kubernetes

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
And that is kubernetes..
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Architecture

mumshad mannambeth
Nodes (Minions)

Node

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster

Node Node Node

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Master

Master Node Node Node

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Components

Container
API Key-value
Controller
Scheduler
kubelet
Kube
etcd store
Runtime
Server

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Master vs Worker Nodes

</> kube-apiserver </> kubelet

etcd

controller

scheduler
Container Runtime

Worker Node CRI-O


Master

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubectl
kubectl run hello-minikube

kubectl cluster-info

kubectl get nodes

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright K odeK l oud


Setup

mumshad mannambeth
Minikube Google Cloud Platform play-with-k8s.com
MicroK8s Amazon Web Services
Kubeadm
Microsoft Azure

Setup Kubernetes
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Minikube
</> kube-apiserver </> kubelet

etcd

node-controller

replica-controller
Container Runtime

Master Worker Node

Minikube

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Minikube

Minikube.exe

Single Node Kubernetes Cluster


kubectl

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
minikube

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD

mumshad mannambeth
Assumptions

Docker Image Kubernetes Cluster

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD

POD POD POD

Node Node Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
POD

POD POD POD

Node Node
Kubernetes Cluster
© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Multi-Container PODs

Network Helper
Containers

POD

Node

© Copyright K odeK l oud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
PODs Again!
docker run python-app

docker run python-app

docker run python-app

docker run python-app

docker run helper –link app1

docker run helper –link app2

docker run helper –link app3 POD POD POD POD


docker run helper –link app4
Node
App Helper Volume

Python App1 Vol1


1
Vol2
Python App2 Note: I am avoiding networking and load balancing details to keep explanation simple.
2
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubectl
kubectl run nginx –-image nginx

kubectl get pods

POD

Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
POD

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
YAML
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
© Copyright KodeKloud Check out our full course on GIT for Beginners: https://kode.wiki/3MUhuve
YAML in Kubernetes
pod-definition.yml
apiVersion: v1 String Kind Version
kind: Pod String
metadata:
POD v1
metadata:
name: myapp-pod Service v1
name: myapp-pod
labels:
labels: Dictionary ReplicaSet apps/v1
app: myapp
app: myapp
type: front-end Deploymen apps/v1
spec: t
containers: List/Arra
- name: nginx-container
y
image: nginx

1st Item in List


kubectl create –f pod-definition.yml
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
YAML in Kubernetes
pod-definition.yml
apiVersion: v1 String Kind Version
kind: Pod String
metadata:
POD v1
metadata:
name: myapp-pod Service v1
name: myapp-pod
labels:
labels: Dictionary ReplicaSet apps/v1
app: myapp
app: myapp
type: front-end Deploymen apps/v1
spec: t
containers: List/Arra
- name: nginx-container
y
image: nginx

1st Item in List


kubectl create –f pod-definition.yml
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Commands
> kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-pod 1/1 Running 0 20s

> kubectl describe pod myapp-pod


Name: myapp-pod
Namespace: default
Node: minikube/192.168.99.100
Start Time: Sat, 03 Mar 2018 14:26:14 +0800
Labels: app=myapp
name=myapp-pod
Annotations: <none>
Status: Running
IP: 10.244.0.24
Containers:
nginx:
Container ID: docker://830bb56c8c42a86b4bb70e9c1488fae1bc38663e4918b6c2f5a783e7688b8c9d
Image: nginx
Image ID: docker-pullable://nginx@sha256:4771d09578c7c6a65299e110b3ee1c0a2592f5ea2618d23e4ffe7a4cab1ce5de
Port: <none>
State: Running
Started: Sat, 03 Mar 2018 14:26:21 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-x95w7 (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 34s default-scheduler Successfully assigned myapp-pod to minikube
Normal SuccessfulMountVolume 33s kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-x95w7"
Normal Pulling 33s kubelet, minikube pulling image "nginx"
Normal Pulled 27s kubelet, minikube Successfully pulled image "nginx"
Normal Created 27s kubelet, minikube Created container
Normal Started 27s kubelet, minikube Started container
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Replication
Controller

mumshad mannambeth
High Availability

POD POD POD


POD
Replication Controller
Replication Controller

Node Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Load Balancing & Scaling

POD POD POD POD

Replication Controller Replication Controller

Node Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Replication Controller Replica Set

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
rc-definition.yml pod-definition.yml
apiVersion: v1 apiVersion: v1
kind: ReplicationController kind: Pod
metadata: Replication Controller
name: myapp-rc metadata:
labels: name: myapp-pod
app: myapp labels:
type: front-end app: myapp
type: front-end
spec: Replication Controller
template: spec:
containers:
POD - name: nginx-container
image: nginx

POD
> kubectl create –f rc-definition.yml
POD replicationcontroller “myapp-rc” created

> kubectl get replicationcontroller


NAME DESIRED CURRENT READY AGE
myapp-rc 3 3 3 19s

replicas: 3 > kubectl get pods


NAME READY STATUS RESTARTS AGE
myapp-rc-4lvk9 1/1 Running 0 20s
myapp-rc-mc2mf 1/1 Running 0 20s
myapp-rc-px9pz 1/1 Running 0 20s
replicaset-definition.yml pod-definition.yml
apiVersion: apps/v1 apiVersion: v1
kind: ReplicaSet kind: Pod
metadata:
error: unable to recognize "replicaset-
name: myapp-replicaset metadata:
labels: definition.yml": no matches for /,name:
Kind=ReplicaSet
myapp-pod
app: myapp labels:
type: front-end app: myapp
type: front-end
spec:
template: spec:
containers:
- name: nginx-container
image: nginx

POD
> kubectl create –f replicaset-definition.yml
replicaset "myapp-replicaset" created

> kubectl get replicaset


NAME DESIRED CURRENT READY AGE
myapp-replicaset 3 3 3 19s

replicas: 3 > kubectl get pods


selector: NAME READY STATUS RESTARTS AGE
matchLabels: myapp-replicaset-9ddl9 1/1 Running 0 45s
myapp-replicaset-9jtpx 1/1 Running 0 45s
type: front-end myapp-replicaset-hq84m 1/1 Running 0 45s
Labels and Selectors
replicaset-definition.yml pod-definition.yml
selector:
metadata:
matchLabels:
name: myapp-pod
tier: POD POD
POD tier: front-end labels:
POD
front-end
POD tier: front-end

POD POD

POD POD POD POD

POD tier: front-end


POD tier: front-end

POD POD

POD POD
POD
POD
POD
POD POD
POD
POD

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
replicaset-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp POD tier: front-end
type: front-end
spec:
template:
metadata:
name: myapp-pod
POD POD
labels: tier: front-end tier: front-end

app: myapp
Template
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
replicaset-definition.yml

Scale apiVersion: apps/v1


kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
> kubectl replace -f replicaset-definition.yml
spec:
template:
metadata:
> kubectl scale -–replicas=6 –f replicaset-definition.yml
name: myapp-pod
labels:
> kubectl scale -–replicas=6 replicaset myapp-replicaset app: myapp
type: front-end
spec:
containers:
TYPE NAME
- name: nginx-container
image: nginx
replicas: 6
3
selector:
matchLabels:
type: front-end
commands
> kubectl create –f replicaset-definition.yml

> kubectl get replicaset

> kubectl delete replicaset myapp-replicaset *Also deletes all underlying PODs
> kubectl replace -f replicaset-definition.yml

> kubectl scale –replicas=6 -f replicaset-definition.yml

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
ReplicaSet

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
ReplicaSet as an Horizontal Pod Autoscaler Target
https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#replicaset-as-an-
horizontal-pod-autoscaler-target

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Deployment

mumshad mannambeth
Deployment v1 v2

POD POD POD POD POD POD POD POD POD

Replica Set

Deployment

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
deployment-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
Deployment
metadata:
Definition name: myapp-deployment
labels:
app: myapp
> kubectl create –f deployment-definition.yml type: front-end
deployment "myapp-deployment" created spec:
template:
> kubectl get deployments metadata:
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE name: myapp-pod
myapp-deployment 3 3 3 3 21s labels:
app: myapp
> kubectl get replicaset type: front-end
NAME DESIRED CURRENT READY AGE spec:
containers:
myapp-deployment-6795844b58 3 3 3 2m
- name: nginx-container
image: nginx
> kubectl get pods
NAME READY STATUS RESTARTS AGE
replicas: 3
myapp-deployment-6795844b58-5rbjl 1/1 Running 0 2m selector:
myapp-deployment-6795844b58-h4w55 1/1 Running 0 2m matchLabels:
myapp-deployment-6795844b58-lfjhv 1/1 Running 0 2m
type: front-end

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
commands
> kubectl get all
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/myapp-deployment 3 3 3 3 9h

NAME DESIRED CURRENT READY AGE


rs/myapp-deployment-6795844b58 3 3 3 9h

NAME READY STATUS RESTARTS AGE


po/myapp-deployment-6795844b58-5rbjl 1/1 Running 0 9h
po/myapp-deployment-6795844b58-h4w55 1/1 Running 0 9h
po/myapp-deployment-6795844b58-lfjhv 1/1 Running 0 9h

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Deployment

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Deployment
Updates and Rollback

mumshad mannambeth
Rollout and Versioning

Revision 1
nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0

Revision 2
nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Rollout Command
> kubectl rollout status deployment/myapp-deployment
Waiting for rollout to finish: 0 of 10 updated replicas are available...
Waiting for rollout to finish: 1 of 10 updated replicas are available...
Waiting for rollout to finish: 2 of 10 updated replicas are available...
Waiting for rollout to finish: 3 of 10 updated replicas are available...
Waiting for rollout to finish: 4 of 10 updated replicas are available...
Waiting for rollout to finish: 5 of 10 updated replicas are available...
Waiting for rollout to finish: 6 of 10 updated replicas are available...
Waiting for rollout to finish: 7 of 10 updated replicas are available...
Waiting for rollout to finish: 8 of 10 updated replicas are available...
Waiting for rollout to finish: 9 of 10 updated replicas are available...
deployment "myapp-deployment" successfully rolled out

> kubectl rollout history deployment/myapp-deployment


deployments "myapp-deployment"
REVISION CHANGE-CAUSE
1 <none>
2 kubectl apply --filename=deployment-definition.yml --record=true

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Deployment Strategy

nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.0 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1 nginx:1.7.1
Recreat
e Application
Down

Rolling nginx:1.7.1
nginx:1.7.0 nginx:1.7.1 nginx:1.7.0 nginx:1.7.1 nginx:1.7.0 nginx:1.7.1 nginx:1.7.0
Updat nginx:1.7.0 nginx:1.7.1
e

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
deployment-definition.yml
apiVersion: apps/v1
kind: Deployment
metadata:
Kubectl apply name: myapp-deployment
labels:
app: myapp
> kubectl apply –f deployment-definition.yml type: front-end
deployment "myapp-deployment" configured spec:
template:
metadata:
> kubectl set image deployment/myapp-deployment \ name: myapp-pod
nginx-container=nginx:1.9.1 labels:
deployment "myapp-deployment" image is updated app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx:1.7.1
replicas: 3
selector:
matchLabels:
type: front-end

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Recreate RollingUpdate
© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Upgrades

POD POD POD POD POD POD POD POD POD POD

Replica Set - 1 Replica Set - 2

Deployment

> kubectl get replicasets


NAME DESIRED CURRENT READY AGE
myapp-deployment-67c749c58c 0 0 0 22m
myapp-deployment-7d57dbdb8d 5 5 5 20m

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Rollback
> kubectl get replicasets > kubectl get replicasets
NAME DESIRED CURRENT READY AGE NAME DESIRED CURRENT READY AGE
myapp-deployment-67c749c58c 0 0 0 22m myapp-deployment-67c749c58c 5 5 5 22m
myapp-deployment-7d57dbdb8d 5 5 5 20m myapp-deployment-7d57dbdb8d 0 0 0 20m

POD POD POD POD POD POD POD POD POD POD

Replica Set - 1 Replica Set - 2

Deployment

> kubectl rollout undo deployment/myapp-deployment


deployment “myapp-deployment” rolled back

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
kubectl run
> kubectl run nginx --image=nginx
deployment "nginx" created

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Summarize Commands
Create > kubectl create –f deployment-definition.yml

Get > kubectl get deployments

> kubectl apply –f deployment-definition.yml


Update
> kubectl set image deployment/myapp-deployment nginx=nginx:1.9.1

> kubectl rollout status deployment/myapp-deployment


Status
> kubectl rollout history deployment/myapp-deployment

Rollback > kubectl rollout undo deployment/myapp-deployment

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Deployment

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright K odeK l oud


Networking 101

mumshad mannambeth
Kubernetes Networking - 101
192.168.1.10
• IP Address is assigned to a POD
192.168.1.2 192.168.1.2

10.244.0.0

10.244.0.3 10.244.0.2 10.244.0.4

POD POD POD

Node Minikube Node


My System
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster Networking
• All containers/PODs can communicate to one
another without NAT 192.168.1.2 192.168.1.3
• All nodes can communicate with all
containers and vice-versa without NAT
10.244.0.0 10.244.0.0

10.244.0.2 10.244.0.2

POD POD

Node Node
Kubernetes Cluster
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster Networking Setup

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Cluster Networking
192.168.1.2 192.168.1.3

10.244.1.0 Routing 10.244.2.0

10.244.1.2 10.244.2.2

POD POD

Node Node

Kubernetes Cluster
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Networking

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Services

mumshad mannambeth
Services
Services

Services
© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
192.168.1.2

10.244.0.0
SSH
>curl http://10.244.0.2
>curl http://192.168.1.2 :30008

3000
Hello World!
Service
?

8
Hello World!

10.244.0.2

192.168.1.10

POD

Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Services Types

NodePort ClusterIP LoadBalancer

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright K odeK l oud


NodePort
Service - NodePort
192.168.1.2

10.244.0.0

>curl http://192.168.1.2:30008

3000
Service
?

8
Hello World!

10.244.0.2

192.168.1.10

POD

Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort

2 Port

10.106.1.1
1 TargetPort
3000

3 NodePort Service

80
8

2
Range: 80
30000 - 32767 10.244.0.2

POD

Node

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
service-definition.yml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
2 Port

10.106.1.1
1 TargetPort
3000

3 NodePort Service
80
spec:
8

Range: 2 80 type: NodePort


30000 - 32767 10.244.0.2 ports:
- targetPort: 80
* port: 80
nodePort: 30008

POD

Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind: Pod
service "myapp-service" created

metadata:
> kubectl get services
name: myapp-service metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name:
ClusterIP
myapp-pod
10.96.0.1 <none> 443/TCP 16d
spec: labels:
myapp-service
NodePort 10.106.127.123 <none> 80:30008/TCP 5m
type: NodePort app: myapp
ports: type: front-end
> curl http://192.168.1.2:30008
- targetPort: 80 spec:
port: 80 containers:
nodePort: 30008 - name: nginx-container
selector: image: nginx

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort

3000
192.168.1.2 8
selector:
Service
app: myapp
Algorithm: Random
SessionAffinity: Yes

10.244.0.3 10.244.0.2 10.244.0.4

labels:
app: myapp
POD POD POD

Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service - NodePort
>curl http://192.168.1.2:30008

>curl http://192.168.1.3:30008

>curl http://192.168.1.4:30008

3000 3000 3000


192.168.1.2 192.168.1.3 8 192.168.1.4 8
8

Service

10.244.0.3 10.244.0.2 10.244.0.4

POD POD POD

Node Node Node

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Service - NodePort

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
ClusterIP

mumshad mannambeth
ClusterIP
10.244.0.3 10.244.0.2 10.244.0.4

front-end POD POD POD

back-end

10.244.0.5 10.244.0.6 10.244.0.7

back-end
POD POD POD

redis
10.244.0.8
10.244.0.5 10.244.0.9 10.244.0.10

redis
POD POD POD

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind:
service “back-end" Pod
created

metadata:
> kubectl get services
name: back-end metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name: myapp-pod
ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: back-end labels:
ClusterIP 10.106.127.123 <none> 80/TCP 2m
type: ClusterIP app: myapp
ports: type: back-end
- targetPort: 80 spec:
port: 80 containers:
- name: nginx-container
selector: image: nginx

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
8080

Voting-app-Pod
Not specified in source code.
Default 6379 assumed

6379 apiVersion: v1
Redis kind: Service
Service metadata:
name: redis
spec:
ports:
6379 - port: 6379
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Service
8080

Voting-app-Pod

7000 apiVersion: v1
Redis kind: Service
Service metadata:
name: some-redis-service
spec:
ports:
6379 - port: 7000
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app

© Copyright KodeKloud Check out our full course on K ubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Demo
Service - NodePort

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
References
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/

© Copyright KodeKloud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Service -
LoadBalancer

mumshad mannambeth
>curl http://192.168.1.2:30008

Services >curl http://myapp.com >curl http://192.168.1.3:30008

>curl http://192.168.1.4:30008

Load
Native Balancer
Load Balancer

3000 3000 3000


192.168.1.2 192.168.1.3 8 192.168.1.4 8
8

Service - NodePort

10.244.0.3 10.244.1.3 10.244.2.3

POD POD POD

Service - ClusterIP

10.244.0.4 10.244.1.4 10.244.2.4

POD POD POD

Node Node Node


© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
service-definition.yml
apiVersion: v1 > kubectl create –f service-definition.yml
kind: Service service “front-end" created

metadata:
> kubectl get services
name: front-end
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: front-end LoaBalancer 10.106.127.123 <Pending> 80/TCP 2m
type: NodePort
LoadBalancer
ports:
- targetPort: 80
port: 80

selector:
app: myapp
type: front-end

© Copyright K odeK l oud Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X
Microservices

mumshad mannambeth
Example voting app
app.py
80 server.js 80
Service Service
POD POD
Goals:
voting-app result-app
1. Deploy Containers
2. Enable Connectivity
3. External Access

POD POD
redis postgres

Service
Service
Steps:
1. Deploy PODs 6379 5432
2. Create Services (ClusterIP)
1. redis
2. db
3. Create Services (NodePort)
program.cs POD
1. voting-app worker
2. result-app
POD POD
voting-app result-app
kodekloud/examplevotingapp_vote:v1 kodekloud/examplevotingapp_result:v1

redis POD POD postgresql


redis postgres

Service
Service
Steps:
1. Deploy PODs
2. Create Services (ClusterIP)
1. redis
2. db
3. Create Services (NodePort) POD
1. voting-app worker
2. result-app
kodekloud/examplevotingapp_worker:v1
Example voting app
Service Service
POD POD
voting-app result-app

POD POD
redis db

Service
Service
POD
worker
Example voting app
Service Service

POD POD POD POD POD POD

voting-app voting-app voting-app result-app result-app result-app

Deployment Deployment

POD POD

Service
Service
redis db

Deployment Deployment

POD
worker

Deployment
Check out our full course on Kubernetes for the Absolute Beginners: https://kode.wiki/43Sv88X

© Copyright KodeKloud
Ansible
For the
Absolute Beginner

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
The
RedHat Ansible for Beginners

Curriculum
Introduction to Ansible

Setting up Ansible on VirtualBox

Inventory Files

Playbooks

Variables

Conditionals

Loops

Roles

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Hands-On Exercises

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Introduction

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Why Ansible?

Configuration Continuous Application Security


Provisioning
Management Delivery Deployment Compliance

• Time • Simple
• Coding Skills • Powerful
• Maintenance • Agentless

Scripts
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Scripts vs Ansible Playbook

#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
- hosts: all_my_db_servers
all_my_web_servers_in_DR
all_my_web_servers_on_cloud
localhost
$username=johndoe tasks:
read -s -p "Enter password : " password - user:
egrep "^$username" /etc/passwd >/dev/null name: johndoe
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
useradd -m -p $password $username
[ $? -eq 0 ] && echo "User has been added
to system!" || echo "Failed to add a user!"
fi
fi

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - Simple

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - complex

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use case example - complex

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Install

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Control Node
Redhat or CentOS – $ sudo yum install ansible

Fedora – $ sudo dnf install ansible

Ubuntu – $ sudo apt-get install ansible


Ansible Control
Machine
• Playbooks
PIP – $ sudo pip install ansible • Inventory
• Modules

Additional Options: • Control Machine - Linux Only


• Install from source on GIT
• Build RPM yourself

https://docs.ansible.com/ansible/latest/installation_guide/
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Install Control Node on Redhat or CentOS

Redhat or CentOS – $ sudo yum install ansible

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Install via PIP
Install pip if not present
$ sudo yum install epel-release

$ sudo yum install python-pip

Install Ansible using pip Upgrade Ansible using pip


$ sudo pip install ansible $ sudo pip install --upgrade ansible

Install Specific Version of Ansible using pip


$ sudo pip install ansible==2.4

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Inventory

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
inventory
server1.company.com
server2.company.com

[mail]
server3.company.com
server4.company.com

[db]
server5.company.com
server6.company.com

[web]
server7.company.com
server8.company.com
Linux – SSH
Windows – Powershell Remoting
inventory
/etc/ansible/hosts Agentless
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
More on inventory files
#Sample Inventory File
web
server1.company.com
ansible_host= ansible_connection=ssh ansible_user=root
db
server2.company.com
ansible_host= ansible_connection=winrm ansible_user=admin
mail
server3.company.com
ansible_host= ansible_connection=ssh ansible_ssh_pass=P@#
web2
server4.company.com
ansible_host= ansible_connection=winrm

localhost ansible_connection=localhost

Inventory Parameters: Security: Ansible Vault


• ansible_connection – ssh/winrm/localhost
• ansible_port – 22/5986
• ansible_user – root/administrator
© Copyright KodeKloud • ansible_ssh_pass - Password Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Ansible

Playbooks

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Ansible playbooks
# Simple Ansible Playbook # Complex Ansible Playbook

- Run command1 on server1 - Deploy 50 VMs on Public Cloud


- Run command2 on server2 - Deploy 50 VMs on Private Cloud
- Run command3 on server3 - Provision Storage to all VMs
- Run command4 on server4 - Setup Network Configuration on Private VMs
- Run command5 on server5 - Setup Cluster Configuration
- Run command6 on server6 - Configure Web server on 20 Public VMs
- Run command7 on server7 - Configure DB server on 20 Private VMs
- Run command8 on server8 - Setup Loadbalancing between web server VMs
- Run command9 on server9 - Setup Monitoring components
- Restarting Server1 - Install and Configure backup clients on VMs
- Restarting Server2 - Update CMDB database with new VM Information
- Restarting Server3
- Restarting Server4
- Restarting Server5
- Restarting Server6
- Restarting Server7

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Playbook
YAML format

• Playbook – A single YAML file playbook.yml


-
• Play – Defines a set of activities name: Play 1
hosts: localhost
(tasks) to be run on hosts tasks:
• Task – An action to be performed on the - name: Execute command ‘date’
host command: date

➢ Execute a command - name: Execute script on server


➢ Run a script script: test_script.sh

➢ Install a package - name: Install httpd service


➢ Shutdown/Restart yum:
name: httpd
state: present

- name: Start web server


service:
name: httpd
© Copyright KodeKloud
state: started
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Playbook format
playbook.yml

-
name: Play 1
hosts: localhost
tasks:
- name: Execute command ‘date’
command: date

- name: Execute script on server


script: test_script.sh

-
name: Play 2
hosts: localhost
tasks:
- name: Install web service
yum:
name: httpd
state: present

- name: Start web server


service:
name: httpd
state: started
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Hosts
playbook.yml inventory
-
name: Play 1
hosts: localhost
localhost
tasks:
- name: Execute command ‘date’ server1.company.com
command: date server2.company.com
- name: Execute script on server
script: test_script.sh [mail]
server3.company.com
- name: Install httpd service
yum:
server4.company.com
name: httpd
state: present [db]
server5.company.com
- name: Start web server
service: server6.company.com
name: httpd
state: started [web]
server7.company.com
server8.company.com

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
module
playbook.yml
- ansible-doc -l
name: Play 1
hosts: localhost
tasks:
- name: Execute command ‘date’
command: date

- name: Execute script on server


script: test_script.sh

- name: Install httpd service


yum:
name: httpd
state: present

- name: Start web server


service:
name: httpd
state: started

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Run
ansible-playbook playbook.yml
• Execute Ansible Playbook
ansible-playbook --help
• Syntax: ansible-playbook <playbook file name>

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright K odeK l oud


Ansible

Modules

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
modules
• System - Win_copy
User
Command
Acl
Mongodb
Amazon
- Group
Expect
Archive
Mssql
Win_command
Atomic
• Commands - Hostname
Raw
Copy
Mysql
Win_domain
Azure
- Iptables
Script
File
Postgresql
Win_file
Centrylink
• Files - Lvg
Shell
Find
Proxysql
Win_iis_website
Cloudscale
• Database -
-
Lvol
Lineinfile
vertica
Win_msg
Cloudstack
Make Ocean
Replace
Win_msi
Digital
• Cloud -
-
Mount
Stat
Win_package
Docker
Ping
Template
Win_ping
Google
• Windows - Timezone
Unarchive
Win_path
Linode
- Systemd
Win_robocopy
Openstack
• More.. - Service
Win_regedit
Rackspace
- Win_shell
Smartos
- Win_service
Softlayer
- Win_user
VMware
- And more

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
command
Executes a command on a remote node
playbook.yml
parameter comments -
chdir cd into this directory before running the command name: Play 1
hosts: localhost
creates a filename or (since 2.0) glob pattern, when it already exists, this step tasks:
will not be run. - name: Execute command ‘date’
command: date
executable change the shell used to execute the command. Should be an absolute
path to the executable.
- name: Display resolv.conf contents
free_form the command module takes a free form command to run. There is no command: cat /etc/resolv.conf
parameter actually named 'free form'. See the examples!
- name: Display resolv.conf contents
command: cat resolv.conf chdir=/etc
removes a filename or (since 2.0) glob pattern, when it does not exist, this step
will not be run. - name: Display resolv.conf contents
command: mkdir /folder creates=/folder
warn if command warnings are on in ansible.cfg, do not warn about this
(added in 1.8) particular line if set to no/false.

- name: Copy file from source to destination


© Copyright KodeKloud Check outcopy:
our full course on Ansible for the Absolute
src=/https/www.scribd.com/source_file Beginners: https://kode.wiki/3No1wef
dest=/destination
script
• Runs a local script on a remote node after transferring it

playbook.yml
-
name: Play 1
hosts: localhost
1. Copy script to remote systems tasks:
2. Execute script on remote systems - name: Run a script on remote server
script: /some/local/script.sh -arg1 -arg2

© Copyright KodeKloud Scripts Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Service
• Manage Services – Start, Stop, Restart

playbook.yml playbook.yml
- -
name: Start Services in order name: Start Services in order
hosts: localhost hosts: localhost
tasks: tasks:
- name: Start the database service - name: Start the database service
service: name=postgresql state=started service:
name: postgresql
state: started
- name: Start the httpd service
service: name=httpd state=started

- name: Start the nginx service


service:
name: nginx
state: started

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
idempotency
Why “started” and not “start”?
“Start” the service httpd ”Started” the service httpd

Ensure service httpd is started

If httpd is not already started => start it


If httpd is already started, =>do nothing

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
lineinfile
• Search for a line in a file and replace it or add it if it doesn’t exist.
/etc/resolv.conf
nameserver 10.1.250.1 nameserver 10.1.250.10
nameserver 10.1.250.2

playbook.yml script.sh
- #Sample script
name: Add DNS server to resolv.conf
hosts: localhost echo “nameserver 10.1.250.10” >> /etc/resolv.conf
tasks:
- lineinfile:
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'
/etc/resolv.conf

/etc/resolv.conf nameserver 10.1.250.1


nameserver 10.1.250.2
nameserver 10.1.250.1 nameserver 10.1.250.10
nameserver 10.1.250.2 nameserver 10.1.250.10
© Copyright KodeKloud
nameserver 10.1.250.10 Check out our full 10.1.250.10
nameserver course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Variables

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Variable
• Stores information that varies with each host
inventory
Web1 ansible_host=server1.company.com ansible_connection=ssh ansible_shh_pass=P@ssW
db ansible_host=server2.company.com ansible_connection=winrm ansible_shh_pass=P@s
Web2 ansible_host=server3.company.com ansible_connection=ssh ansible_shh_pass=P@ssW

Playbook.yml variables
- variable1: value1
name: Add DNS server to resolv.conf variable2: value2
hosts: localhost
tasks:
vars:
- lineinfile:
dns_server: 10.1.250.10
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Using variables

Playbook.yml
-
name: Add DNS server to resolv.conf
hosts: localhost
vars:
dns_server: 10.1.250.10
tasks:
- lineinfile:
path: /etc/resolv.conf
line: 'nameserver {{ dns_server }}’
10.1.250.10'

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- #Sample Inventory File
name: Set Firewall Configurations
hosts: web
Web http_port= snmp_port= inter_ip_range=
tasks:
- firewalld:
service: https
permanent: true #Sample variable File – web.yml
state: enabled
http_port: 8081
- firewalld: snmp_port: 161-162
port: 8081
‘{{/tcp
http_port }}’/tcp inter_ip_range: 192.0.2.0
permanent: true
state: disabled

- firewalld:
161-162
port: ‘{{ snmp_port
/udp }}’/udp
permanent: true
state: disabled {{ }}
- firewalld: Jinja2 Templating
source: 192.0.2.0
‘{{ inter_ip_range
/24 }}’/24
Zone: internal
state: enabled source: {{ inter_ip_range }}

source: ‘{{ inter_ip_range }}’


© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
source: SomeThing{{ inter_ip_range }}SomeThing
Ansible

Loops

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
LOOPS
- - var: item=joe
name: Create
user: users
name= “{{ item }}” state=present
hosts: localhost
tasks:
- user: name= joe
‘{{ item }}’ state=present
- loop:
user: name=george state=present
- user:
- joename=ravi state=present
- user: name=mani
- george state=present
- user: name=kiran
- ravi state=present
- user: name=jazlan
- mani state=present
- user: name=emaan
- kiran state=present
- user: name=mazin
- jazlan state=present
- user: name=izaan
- emaan state=present
- user: name=mike
- mazin state=present
- user: name=menaal
- izaan state=present
- user: name=shoeb
- mike state=present
- user: name=rani
- menaal state=present
- shoeb
- rani

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present
loop: - var: item=
- joe user: name= “{{ item }}” state=present
- george
- ravi - var: item=
- mani user: name= “{{ item }}” state=present
- kiran - var: item=
- jazlan user: name= “{{ item }}” state=present
- emaan
- var: item=
- mazin
user: name= “{{ item }}” state=present
- izaan
- mike - var: item=
- menaal user: name= “{{ item }}” state=present
- shoeb - var: item=
- rani user: name= “{{ item }}” state=present
- var: item=
user: name= “{{ item }}” state=present
- var: item=
© Copyright KodeKloud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
- var: item=
user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present
loop: - var: item=joe
- joe user: name= “{{ item }}” state=present
- george
- ravi - var: item= george
- mani user: name= “{{ item }}” state=present
- kiran - var: item= ravi
- jazlan user: name= “{{ item }}” state=present
- emaan
- var: item= mani
- mazin
user: name= “{{ item }}” state=present
- izaan
- mike - var: item= kiran
- menaal user: name= “{{ item }}” state=present
- shoeb - var: item= jazlan
- rani user: name= “{{ item }}” state=present
- var: item= emaan
user: name= “{{ item }}” state=present
- var: item= mazin
© Copyright KodeKloud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
- var: item= izaan
user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ ???? item }}’ ‘{{ ? }}’
state=present uid=1010
loop: - var: item=joe
-- name:
joe 1010
joe user: name= “{{ item }}” state=present
- uid:
george 1011
1010
- var: item=george
-- name:
ravi george 1012
- uid:
mani 1011 1013 user: name= “{{ item }}” state=present
-- name:
kiran ravi 1014 - var: item=ravi
- uid:
jazlan 1015
1012 user: name= “{{ item }}” state=present
-- name:
emaan mani 1016
- var: item=mani
- uid:
mazin1013 1017
user: name= “{{ item }}” state=present
-- name:
izaan kiran 1018
- uid:
mike 1014 1019 - var: item=kiran
-- name:
menaaljazlan1020 user: name= “{{ item }}” state=present
- uid:
shoeb1015 1021 - var: item=jazlan
-- name:
rani emaan 1022 user: name= “{{ item }}” state=present
uid: 1016 - var: item=emaan
- name: mazin user: name= “{{ item }}” state=present
uid: 1017 - var: item=mazin
- name: izaan
© Copyright K odeK l oud Check out our fulluser: name=
course on “{{
Ansible for item }}”
the Absolute state=present
Beginners: https://kode.wiki/3No1wef
uid: 1018 - var: item=izaan
- name: mike user: name= “{{ item }}” state=present
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
item }}’
- user: name=‘{{ ???? ‘{{ ? }}’
state=present uid=1010 - var:
loop: item:
-- name:
joe joe1010
- uid:
george 10101011
-- name:
ravi george 1012 user: name= “{{ ???? }}” state=present uid=“{?}”
- uid:
mani 10111013 - var:
-- name:
kiran ravi 1014 item:
- uid:
jazlan 10121015
-- name:
emaan mani 1016
- uid:
mazin10131017 user: name= “{{ ???? }}” state=present uid=“{?}”
-- name:
izaan kiran 1018
- uid:
mike 10141019 - var:
-- name:
menaaljazlan 1020 item:
- uid:
shoeb10151021
-- name:
rani emaan 1022
uid: 1016 user: name= “{{ ???? }}” state=present uid=“{?}”
- name: mazin - var:
uid: 1017 item:
- name: izaan
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018
- name: mike user: name= “{{ ???? }}” state=present uid=“{?}”
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ ???? item }}’ ‘{{ ? }}’
state=present uid=1010 - var:
loop: item:
-- name:
joe joe1010 name: joe
- uid:
george 10101011 uid: 1010
-- name:
ravi george 1012 user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid }
- uid:
mani 10111013
- var:
-- name:
kiran ravi 1014
item:
- uid:
jazlan 10121015 name: george
-- name:
emaan mani 1016 uid: 1011
- uid:
mazin10131017
user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid
-- name:
izaan kiran 1018
- uid:
mike 10141019 - var:
-- name:
menaaljazlan 1020 item:
- uid:
shoeb10151021 name: ravi
-- name:
rani emaan 1022 uid: 1012
uid: 1016 user: name= ‘{{ “{{item.name
???? }}” }}’ state=present uid=“{?}” ‘{{ item.uid }
- name: mazin - var:
uid: 1017 item:
- name: izaan name: mani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018 uid: 1013
- name: mike user: name=‘{{ “{{ ???? }}”
item.name }}’ state=present uid=“{?}” ‘{{ item.uid }
LOOPS - Visualize
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name= ‘{{ item }}’
‘{{item.name
???? ‘{{item.uid
}}’ state=present uid=1010
‘{{ ? }}’ }}’ - var:
loop: item:
1010 name: joe
-- name:
joe joe - { name: joe, uid: 1010 }
- uid:
george 1011 uid: 1010
1010
1012 user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid }
-- name:
ravi george - { name: george, uid: 1011 }
- uid:
mani 1011 1013
- var:
1014
-- name:
kiran ravi - { name: ravi, uid: 1012 } item:
- uid:
jazlan 1015 name: george
1012
1016
-- name:
emaan mani - { name: mani, uid: 1013 } uid: 1011
- uid:
mazin1013 1017
user: name=‘{{
“{{ ???? }}”
item.name }}’ state=present uid=“{?}”
‘{{ item.uid
1018
-- name:
izaan kiran - { name: kiran, uid: 1014 }
- uid:
mike 1014 1019 - var:
1020
-- name:
menaaljazlan - { name: jazlan, uid: 1015 } item:
- uid:
shoeb1015 1021 name: ravi
1022 uid: 1012
-- name:
rani emaan - { name: emaan, uid: 1016 }
uid: 1016 user: name= ‘{{ “{{item.name
???? }}” }}’ state=present uid=“{?}” ‘{{ item.uid }
- name: mazin - { name: mazin, uid: 1017 } - var:
uid: 1017 item:
- name: izaan - { name: izaan, uid: 1018 } name: mani
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
uid: 1018 uid: 1013
- name: mike - { name: mike, uid: 1019 } user: name=‘{{ “{{ ???? }}”
item.name }}’ state=present uid=“{?}” ‘{{ item.uid }
With_*
- -
name: Create users name: Create users
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present - user: name=‘{{ item }}’ state=present
loop: with_items:
- joe - joe
- george - george
- ravi - ravi
- mani - mani

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
With_*
- -
name: Create users name: View Config Files
hosts: localhost hosts: localhost
tasks: tasks:
- user: name=‘{{ item }}’ state=present - debug: var=item
with_items: with_file:
- joe - “/etc/hosts”
- george - “/etc/resolv.conf”
- ravi - “/etc/ntp.conf”
- mani

- -
name: Get from multiple URLs name: Check multiple mongodbs
hosts: localhost hosts: localhost
tasks: tasks:
- debug: var=item - debug: msg=“DB={{ item.database }} PID={{ item.pid}}”
with_url: with_mongodb:
- “https://site1.com/get-servers” - database: dev
- “https://site2.com/get-servers” connection_string: “mongodb://dev.mongo/”
- “https://site3.com/get-servers” - database: prod
connection_string: “mongodb://prod.mongo/”
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
With_*
with_items With_redis
with_file With_sequence
with_url With_skydive
with_mongodb With_subelements
with_dict With_template
with_etcd With_together
with_env With_varnames
with_filetree
With_ini
With_inventory_hostnames
With_k8s
With_manifold
With_nested
With_nios
With_openshift
With_password
With_pipe
© Copyright KodeKloud
With_rabbitmq Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Conditionals

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
--- ---
- name: Install NGINX - name: Install NGINX
hosts: debian_hosts hosts: redhat_hosts
tasks: tasks:
- name: Install NGINX on Debian - name: Install NGINX on Redhat
apt:
apt yum:
yum
name: nginx name: nginx
state: present state: present

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

NOTE: PARTS OF CODE HIDDEN FOR BREVITY


Conditional - when

---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
apt
name: nginx
state: present
when: ansible_os_family
<< condition >> == “Debian”

- name: Install NGINX on Redhat


yum:
yum
name: nginx
state: present
when: ansible_os_family
<< condition >> == “RedHat”
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Operator - or
---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
apt
name: nginx
state: present
when: ansible_os_family
<< condition >> == “Debian”

- name: Install NGINX on Redhat


yum:
yum
name: nginx
state: present
when: ansible_os_family
<< condition >> == “RedHat” or
ansible_os_family == “SUSE”

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Operator - and
---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
apt
name: nginx
state: present
when: ansible_os_family
<< condition >> == “Debian” and
ansible_distribution_version == “16.04”

- name: Install NGINX on Redhat


yum:
yum
name: nginx
state: present
when: ansible_os_family
<< condition >> == “RedHat” or
ansible_os_family == “SUSE”
© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Conditionals in Loops
---
- name: Install NGINX
hosts: all
tasks:
- name: Install NGINX on Debian
apt:
name: nginx
state: present

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Conditionals in Loops
---
- name: Install Softwares
hosts: all
vars:
packages:
- name: nginx
required: True
- name: mysql
required : True
- name: apache
required : False
tasks:
- name:
- name:name: Install
Install “{{
Install “{{ item.name
“{{ item.name
item.name }}” }}”
}}” on
on Debian
Debian
on Debian
vars:
vars:
apt:item:
item:
name:
name:“{{
nginx
name: item.name }}”
nginx
mysql
apache
state: present
required:
required: True
False
apt:
apt:
name: “{{ item.name }}”
state: present
© Copyright KodeKloud
loop: "{{ packages }}" Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- name: Install “{{ item.name }}” on Debian

Conditionals in Loops vars:


item:
name: nginx
required: True
apt:
--- name: “{{ item.name }}”
- name: Install Softwares state: present
hosts: all when: item.required == True
vars:
packages: - name: Install “{{ item.name }}” on Debian
vars:
- name: nginx item:
required: True name: mysql
- name: mysql required: True
required : True apt:
name: “{{ item.name }}”
- name: apache state: present
required : False when: item.required == True
tasks:
- name: Install “{{ item.name }}” on Debian - name: Install “{{ item.name }}” on Debian
apt: vars:
item:
name: “{{ item.name }}”
nginx name: apache
state: present required: False
apt:
name: “{{ item.name }}”
© Copyright KodeKloud
state: present
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
loop: "{{ packages }}"
when: item.required == True
Conditionals in Loops
---
- name: Install Softwares
hosts: all
vars:
packages:
- name: nginx
required: True
- name: mysql
required : True
- name: apache
required : False
tasks:
- name:
- name:name: Install
Install “{{
Install “{{ item.name
“{{ item.name
item.name }}” }}”
}}” on
on Debian
Debian
on Debian
vars:
vars:
apt:item:
item:
name:
name:“{{
nginx
name: item.name }}”
nginx
mysql
apache
state: present
required:
required: True
False
apt:
apt:
when:name:item.required
“{{ item.name }}”== True
state: present
© Copyright KodeKloud
loop: "{{ packages }}" Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Conditionals & Register

- name: Check status of a service and email if its down


hosts: localhost
tasks:
- command: service httpd status
register: result

- mail:
to: [email protected]
subject: Service Alert
body: Httpd Service is down
when: result.stdout.find('down') != -1

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Ansible

Roles

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor

Engineer

Astronaut

Police

Chef
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor mysql

Engineer nginx

Astronaut redis

Police backup

Chef monitor
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Doctor mysql
• Go to medical school
• Installing Pre-requisites
• Earn medical degree
• Installing mysql packages
• Complete Residency Program
• Configuring mysql service
• Obtain License
• Configuring database and users

Engineer nginx
• Installing Pre-requisites
• Go to engineering school • Installing nginx packages
• Earn bachelor’s degree • Configuring nginx service
• Gain field experience • Configuring custom web pages
• Gain postgraduate degree

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
- name: Install and Configure MySQL
hosts: db-server
tasks: mysql
- name: Install Pre-Requisites
• Installing Pre-requisites
yum: name=pre-req-packages state=present
• Installing mysql packages
• Configuring mysql service
- name: Install MySQL Packages • Configuring database and users
yum: name=mysql state=present
nginx
- name: Start MySQL Service
service: name=mysql state=started • Installing Pre-requisites
• Installing nginx packages
• Configuring nginx service
- name: Configure Database • Configuring custom web pages
mysql_db: name=db1 state=present

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
mysql
• Installing Pre-requisites
• Installing mysql packages
Re-Use • Configuring mysql service
• Configuring database and users

- name: Install and Configure MySQL


hosts: db-server1……db-server100
MySQL-Role
tasks:
roles:
- name: Install Pre-Requisites
- mysql
yum: name=pre-req-packages state=present

- name: Install MySQL Packages


yum: name=mysql state=present

- name: Start MySQL Service


service: name=mysql state=started

- name: Configure Database


mysql_db: name=db1 state=present

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
mysql
• Installing Pre-requisites
• Installing mysql packages
Organize Re-Use • Configuring mysql service
• Configuring database and users

MySQL-Role

tasks vars handlers


tasks:
mysql_packages:
- name: Install Pre-Requisites
- mysql
yum: name=pre-req-packages state=present
- mysql-server
db_config:
- name: Install MySQL Packages
db_name: db1
yum: name=mysql state=present

- name: Start MySQL Service


service: name=mysql state=started defaults templates
- name: Configure Database mysql_user_name: root
mysql_db: name=db1 state=present mysql_user_password: root

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share

$ ansible-galaxy init mysql playbook.yml


- name: Install and Configure MySQL
mysql my-playbook hosts: db-server
README.md playbook.yml roles:
- mysql
templates roles
tasks
handlers
vars
defaults
meta

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share

$ ansible-galaxy init mysql playbook.yml


- name: Install and Configure MySQL
mysql my-playbook hosts: db-server
README.md playbook.yml roles:
- mysql
templates roles
tasks
handlers
vars
defaults
meta

© Copyright K odeK l oud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Organize Re-Use Share

$ ansible-galaxy init mysql playbook.yml


my-playbook - name: Install and Configure MySQL
hosts: db-server
playbook.yml
roles:
roles - mysql
mysql

README.md
templates
tasks
/etc/ansible/ansible.cfg handlers
roles_path = /etc/ansible/roles vars
defaults
© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
meta
Organize Re-Use Share

$ ansible-galaxy init mysql playbook.yml


- name: Install and Configure MySQL
my-playbook hosts: db-server
roles:
playbook.yml - mysql

roles
mysql

README.md
templates
tasks
handlers
vars
defaults
© Copyright KodeKloud meta Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Find Roles
$ ansible-galaxy search mysql
Found 1126 roles matching your search. Showing first 1000.

Name Description
---- -----------
0utsider.ansible_zabbix_agent Installing and maintaining zabbix-agent for
1mr.unattended install and configure unattended upgrade
1nfinitum.mysql Simply installs MySQL 5.7 on Xenial.
4linuxdevops.mysql-server Instalacao e Configuracao do servidor MySQL
5KYDEV0P5.skydevops-mysql Install and configure MySQL Database
AAbouZaid.yourls Manage Yourls, a URL shortener web app.
AAROC.AAROC_fg-db your description
aaronpederson.ansible-autodeploy Simple deployment tool with hooks
abednarik.mysqld-exporter Install and configure mysqld_exporter
abelboldu.openstack-glance
abelboldu.openstack-keystone
abelboldu.openstack-neutron-controller OpenStack Neutron controller node
abelboldu.openstack-nova-controller OpenStack Nova controller node
achaussier.mysql-backup configure mysql-backup with xtrabackup and
achaussier.mysql-server Install mysql-server package
achilleskal.ansible_mysql8 your description
adarnimrod.mysql Provision a MySQL server

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use Role
$ ansible-galaxy install geerlingguy.mysql
- downloading role 'mysql', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-mysql/archive/2.9.5.tar.gz
- extracting geerlingguy.mysql to /etc/ansible/roles/geerlingguy.mysql
/etc/ansible/roles/geerlingguy.mysql
- geerlingguy.mysql (2.9.5) was installed successfully

playbook.yml
- -
name: Install and Configure MySQL name: Install and Configure MySQL
hosts: db-server hosts: db-server
roles: roles:
- geerlingguy.mysql - role: geerlingguy.mysql
become: yes
vars:
mysql_user_name: db-user

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Use Role
Playbook-all-in-one.yml Playbook-distributed.yml
- -
name: Install and Configure MySQL name: Install and Configure MySQL
hosts: db-and-webserver hosts: db-server
roles: roles:
- geerlingguy.mysql - geerlingguy.mysql
- nginx
-
name: Install and Configure Web Server
hosts: web-server
roles:
- nginx

mysql

mysql

© Copyright K odeK l oud nginx


Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
List Roles
$ ansible-galaxy list
- geerlingguy.mysql
- kodekloud1.mysql

$ ansible-config dump | grep ROLE


EFAULT_PRIVATE_ROLE_VARS(default) = False
DEFAULT_ROLES_PATH(default) = [u'/root/.ansible/roles', u'/usr/share/ansible/roles', u'/etc/ansible/roles']
GALAXY_ROLE_SKELETON(default) = None
GALAXY_ROLE_SKELETON_IGNORE(default) = ['^.git$', '^.*/.git_keep$']

$ ansible-galaxy install geerlingguy.mysql –p ./roles

© Copyright KodeKloud Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef
Check out our full course on Ansible for the Absolute Beginners: https://kode.wiki/3No1wef

© Copyright KodeKloud
Traditional IT &
Challenges
Field Engineers
Procurement

System/ NW

Infrastructure Team
Administrators

Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead

Backup Admins

Application team
Data Center
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Field Engineers
Procurement

System/ NW

Infrastructure Team
Administrators

Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead

Slow Deployment

Expensive
Backup Admins

Limited Automation

Human Error Inconsistency


Application team
Data Center
Wasted Resources
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Field Engineers
Procurement

System/ NW

Infrastructure Team
Administrators

Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead

Slow Deployment

Expensive
Backup Admins

Limited Automation

Human Error Inconsistency


Application team
Data Center
Wasted Resources
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Field Engineers
Procurement

System/ NW

Infrastructure Team
Administrators

Solution Architect
Business Business Analyst Storage Admins
/ Technical Lead

Backup Admins
Slow Delivery

Human Error Inconsistency


Application team
Data Center
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Shell Python Ruby
Perl Powershell

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Infrastructure as
Code
Infrastructure as Code
ec2.sh
#!/bin/bash

IP_ADDRESS="10.2.2.1"

EC2_INSTANCE=$(ec2-run-instances --instance-type
t2.micro ami-0edab43b6fa892279)

INSTANCE=$(echo ${EC2_INSTANCE} | sed 's/*INSTANCE //'


| sed 's/ .*//')

# Wait for instance to be ready


while ! ec2-describe-instances $INSTANCE | grep -q
"running"
do
echo Waiting for $INSTANCE is to be ready...
done

# Check if instance is not provisioned and exit


if [ ! $(ec2-describe-instances $INSTANCE | grep -q
"running") ]; then
echo Instance $INSTANCE is stopped.
exit
fi

ec2-associate-address $IP_ADDRESS -i $INSTANCE

echo Instance $INSTANCE was created successfully!!!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code
ec2.sh main.tf
#!/bin/bash
resource "aws_instance" "webserver" {
IP_ADDRESS="10.2.2.1"
ami = "ami-0edab43b6fa892279"
EC2_INSTANCE=$(ec2-run-instances --instance-type instance_type = "t2.micro"
t2.micro ami-0edab43b6fa892279) }
INSTANCE=$(echo ${EC2_INSTANCE} | sed 's/*INSTANCE //'
| sed 's/ .*//')

# Wait for instance to be ready


while ! ec2-describe-instances $INSTANCE | grep -q
"running"
do
echo Waiting for $INSTANCE is to be ready...
done

# Check if instance is not provisioned and exit


if [ ! $(ec2-describe-instances $INSTANCE | grep -q
"running") ]; then
echo Instance $INSTANCE is stopped.
exit
fi

ec2-associate-address $IP_ADDRESS -i $INSTANCE

echo Instance $INSTANCE was created successfully!!!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Infrastructure as Code
ec2.yaml main.tf

- amazon.aws.ec2: resource "aws_instance" "webserver" {


key_name: mykey ami = "ami-0edab43b6fa892279"
instance_type: t2.micro instance_type = "t2.micro"
image: ami-123456 }
wait: yes
group: webserver
count: 3
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools

Configuration Management Server Templating Provisioning Tools

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Types of IAC Tools

Configuration Management
Designed to Install and Manage Software

Maintains Standard Structure

Version Control

Idempotent

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Server Templating Tools

Pre Installed Software and Dependencies

Virtual Machine or Docker Images

Immutable Infrastructure

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Provisioning Tools

Deploy Immutable Infrastructure resources

Servers, Databases, Network Components etc.

Multiple Providers

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Terraform
Why Terraform?

Physical Machines

VMWare

AWS

GCP

Azure

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers

Physical Machines BigIP

VMWare CloudFlare

AWS DNS

GCP Palo Alto

Azure Infoblox

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers

Physical Machines BigIP DataDog

VMWare CloudFlare Grafana

AWS DNS Auth0

GCP Palo Alto Wavefront

Azure Infoblox Sumo Logic

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Providers

Physical Machines BigIP DataDog InfluxDB

VMWare CloudFlare Grafana MongoDB

AWS DNS Auth0 MySQL

GCP Palo Alto Wavefront PostgreSQL

Azure Infoblox Sumo Logic VCS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HashiCorp Configuration Language

main.tf

resource "aws_instance" "webserver" {


ami = "ami-0edab43b6fa892279"
instance_type = "t2.micro"
}

resource "aws_s3_bucket" "finance" {


bucket = "finanace-21092020"
tags = {
Description = "Finance and Payroll"
}
}
resource "aws_iam_user" "admin-user" {
name = "lucy"
tags = {
Description = "Team Leader"
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Declarative

main.tf Real World Infrastructure

resource "aws_instance" "webserver" {


ami = "ami-0edab43b6fa892279"
instance_type = "t2.micro"
}

resource "aws_s3_bucket" "finance" {


bucket = "finanace-21092020"
tags = {
Description = "Finance and Payroll"
}
}
resource "aws_iam_user" "admin-user" {
name = "lucy"
tags = {
Description = "Team Leader"
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Declarative

main.tf Real World Infrastructure

resource "aws_instance" "webserver" {


ami = "ami-0edab43b6fa892279"
instance_type = "t2.micro" Init
}

resource "aws_s3_bucket" "finance" { Plan


bucket = "finanace-21092020"
tags = {
Description = "Finance and Payroll"
} Apply
}
resource "aws_iam_user" "admin-user" {
name = "lucy"
tags = {
Description = "Team Leader"
}
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource

Real World Infrastructure

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State

terraform.tfstate Real World Infrastructure

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Import

terraform.tfstate Real World Infrastructure

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Cloud and Terraform Enterprise

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright K odeK l oud


Installing Terraform
>_
$ wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
$ unzip terraform_0.13.0_linux_amd64.zip
$ mv terraform /usr/local/bin

$ terraform version
Terraform v0.13.0

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HCL – Declarative Language

aws.tf

resource "aws_instance" "webserver" {


ami = "ami-0c2f25c1f66a1ff4d"
instance_type = "t2.micro"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HCL Basics
>_
$ mkdir /root/terraform-local-file
$ cd /root/terraform-local-file

local.tf

resource "local_file"
<block> <parameters> { "pet" {​
filename = "/root/pets.txt"​
key1 = value1
key2 = value2
content = "We love pets!"​
}}

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local=provider
file=resource
Block Resource Resource
Name Type Name
FILENAME CONTENT

local.tf

resource "local_file" "pet" {​


{
filename = "/root/pets.txt"​
Arguments
content = "We love pets!"​
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
aws-ec2.tf

resource "aws_instance" "webserver" {


ami = "ami-0c2f25c1f66a1ff4d"
instance_type = "t2.micro"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
aws-s3.tf

resource "aws_s3_bucket" "data" {


bucket = "webserver-bucket-org-2207"
acl = "private"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = "We love pets!"
}

Init Plan Apply

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = "We love pets!"
}

>_
$ terraform init
Initializing the backend...

Initializing provider plugins...


- Finding latest version of hashicorp/local...
- Installing hashicorp/local v1.4.0...
- Installed hashicorp/local v1.4.0 (signed by HashiCorp)

The following providers do not have any version constraints in configuration,


so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* hashicorp/local: version = "~> 1.4.0"

Terraform has been successfully initialized!


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

An execution plan has been generated and is shown below.


Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# local_file.pet will be created


+ resource "local_file" "pet" {
+ content = "We love pets!"
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pets.txt"
+ id = (known after apply)
}

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so


Terraform
can't guarantee that exactly these actions will be performed if
© Copyright KodeKloud"terraform apply" is subsequently run. Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# local_file.pet will be created


+ resource "local_file" "pet" {
+ content = "We love pets!"
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pets.txt"
+ id = (known after apply)
}

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes


local_file.new_file: Creating...
local_file.new_file: Creation complete after 0s
[id=521c5c732c78cb42cc9513ecc7c0638c4a115b55]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

$ cat /root/pets.txt
© Copyright KodeKloud We love pets! Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform show
# local_file.pet:
resource "local_file" “pet" {
content = "We love pets!"
directory_permission = "0777"
file_permission = "0777"
filename = "/root/pets.txt"
id = "cba595b7d9f94ba1107a46f3f731912d95fb3d2c"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local=provider
file=resource
Resource
Type

local.tf

resource "local_file" "pet" {​


filename = "/root/pets.txt"​
content = "We love pets!"​
}

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
provider

resource_type

Argument-1 Argument-1 Argument-1 Argument-1 Argument-1 Argument-1

Arguments Argument-2 Argument-2 Argument-2 Argument-2 Argument-2 Argument-2

Argument-X Argument-X Argument-X Argument-X Argument-X Argument-X

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
https://registry.terraform.io/providers/hashicorp/local/latest/docs
provider Local provider

resource_type local_file

filename (required)
Content (optional)
Arguments file_permission (optional)
directory_permission (optional)
sensitive_content (optional)
content_base64 (optional)

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Update and Destroy
Infrastructure
>_

$ terraform plan
local_file.pet: Refreshing state...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

----------------------------------------------------------------------
local.tf An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
resource "local_file" "pet" { -/+ destroy and then create replacement

filename = "/root/pets.txt" Terraform will perform the following actions:


content = "We love pets!"
# local_file.pet must be replaced
file_permission = "0700" -/+ resource "local_file" "pet" {
content = "We love pets!"
} directory_permission = "0777"
~ file_permission = "0777" -> "0700" # forces replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.

----------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so
Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
$ ls -ltr /root/pets.txt
$ terraform apply
-rwx------ 1 root root 30 Aug 17 23:20 pet.txt
# local_file.pet must be replaced
-/+ resource "local_file" "pet" {
content = "We love pets!"
directory_permission = "0777"
~ file_permission = "0777" -> "0700" # forces replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet: Destruction complete after 0s
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform destroy
local_file.pet: Refreshing state...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

An execution plan has been generated and is shown below.


Resource actions are indicated with the following symbols:
- destroy

Terraform will perform the following actions:

# local_file.pet will be destroyed


- resource "local_file" "pet" {
- content = "My favorite pet is a gold fish" -> null
- directory_permission = "0777" -> null
- file_permission = "0700" -> null
- filename = "/root/pet.txt" -> null
- id = "5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -
> null
}

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?


Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.

Enter a value: yes

local_file.pet: Destroying... [id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]


local_file.pet: Destruction complete after 0s

© Copyright KodeKloud Destroy complete!


Check out Resources: 1 Terraform
our full course on destroyed.
for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Basics
Using Terraform
Providers
>_

$ terraform init

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Official

Verified

Community

© Copyright KodeKloud
registry.terraform.i
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
o
>_ >_
$ terraform init $ ls /root/terraform-local-file/.terraform
Initializing the backend... plugins

Initializing provider plugins...


- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by HashiCorp)

The following providers do not have any version constraints in


configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may


contain breaking
changes, we recommend adding version constraints in a
required_providers block
in your configuration, with the constraint strings suggested
below.

* hashicorp/local: version = "~> 2.0.0"

Terraform has been successfully initialized!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform init
Initializing the backend...

Initializing provider plugins...


- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by HashiCorp)

The following providers do not have any version constraints in


configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may


contain breaking
changes, we recommend adding version constraints in a
required_providers block
in your configuration, with the constraint strings suggested
below.

* hashicorp/local: version = "~> 2.0.0"

Terraform has been successfully initialized!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
To prevent automatic upgrades to new maj
contain breaking
changes, we recommend adding version con
required_providers block
in your configuration, with the constrai
below.

* hashicorp/local: version = "~> 2.0.0"

Organizational
Type
Namespace

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
To prevent automatic upgrades to new maj
contain breaking
changes, we recommend adding version con
required_providers block
in your configuration, with the constrai
below.

* registry.terraform.io/ hashicorp/loc

Hostname Organizational
Ty
Namespace

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by Ha

The following providers do not have any version


configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versi


contain breaking
changes, we recommend adding version constraints
required_providers block
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Configuration
Directory
>_
[terraform-local-file]$ ls /root/terraform-local-file
local.tf

local.tf cat.tf

resource "local_file" "pet" { resource "local_file" "cat" {


filename = "/root/pets.txt" filename = "/root/cat.txt"
content = "We love pets!" content = "My favorite pet is Mr. Whiskers"
}
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local.tf cat.tf

main.tf
File Name Purpose
resource "local_file" "pet" {
Main configuration file containing resource
filename = "/root/pets.txt" main.tf
definition
content = "We love pets!"
} variables.tf Contains variable declarations

resource "local_file" "cat" { outputs.tf Contains outputs from resources


filename = "/root/cat.txt"
content = "My favorite pet is Mr. Whiskers" provider.tf Contains Provider definition

}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Multiple Providers
main.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = "We love pets!"
}

resource "random_pet" "my-pet" {


prefix = "Mrs"
separator = "."
length = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_

$ terraform init
Initializing the backend...

Initializing provider plugins...


- Using previously-installed hashicorp/local v2.0.0
- Finding latest version of hashicorp/random...
- Installing hashicorp/random v2.3.0...
- Installed hashicorp/random v2.3.0 (signed by HashiCorp)

The following providers do not have any version constraints in


configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain


breaking
changes, we recommend adding version constraints in a required_providers
block
in your configuration, with the constraint strings suggested below.

* hashicorp/local: version = "~> 2.0.0"


* hashicorp/random: version = "~> 2.3.0"

Terraform has been successfully initialized!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be
persisted to local or remote state storage.

local_file.pet: Refreshing state...


[id=d1a31467f206d6ea8ab1cad382bc106bf46df69e]

.
.
# random_pet.my-pet will be created
+ resource "random_pet" "my-pet" {
+ id = (known after apply)
+ length = 1
+ prefix = "Mrs"
+ separator = "."
}

Plan: 1 to add, 0 to change, 0 to destroy.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
local_file.new_file: Refreshing state...
[id=d1a31467f206d6ea8ab1cad382bc106bf46df69e]

An execution plan has been generated and is shown below.


Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# random_pet.my-pet will be created


+ resource "random_pet" "my-pet" {
Mrs.hen
+ id = (known after apply)
+ length = 1
+ prefix = "Mrs"
+ separator = "."
}

Plan: 1 to add, 0 to change, 0 to destroy.

random_pet.my-pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mrs.hen]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Define Input
Variables
main.tf
Argument Value
resource "local_file" "pet" {
filename = "/root/pets.txt" filename "/root/pets.txt"
content = "We love pets!"
content "We love pets!"
}
prefix "Mrs"
resource "random_pet" "my-pet" {
prefix = "Mrs" separator "."
separator = "."
length "1"
length = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = "/root/pets.txt" default = "/root/pets.txt"
content = "We love pets!" }
variable "content" {
} default = "We love pets!"
}
resource "random_pet" "my-pet" { variable "prefix" {
prefix = "Mrs" default = "Mrs"
separator = "." }
length = "1" variable "separator" {
} default = "."
}
variable "length" {
default = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename
"/root/pets.txt" default = "/root/pets.txt"
var.content
content = "We love pets!" }
variable "content" {
} default = "We love pets!"
}
resource "random_pet" "my-pet" { variable "prefix" {
prefix = var.prefix
"Mrs" default = "Mrs"
separator = var.separator
"." }
length = var.length
"1" variable "separator" {
} default = "."
}
variable "length" {
default = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
# local_file.pet will be created
+ resource "local_file" "pet" {
+ content = “We love pets!"
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pet.txt"
+ id = (known after apply)
}

# random_pet.my-pet will be created


+ resource "random_pet" "my-pet" {
+ id = (known after apply)
+ length = 1
+ prefix = "Mrs"
+ separator = "."
}

Plan: 2 to add, 0 to change, 0 to destroy.


.
.
random_pet.my-pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mrs.ram]
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=f392b4bcf5db76684f719bf72061627a9a177de1]
© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename
"/root/pets.txt" default = "/root/pets.txt"
var.content
content = "We love pets!" }
variable "content" {
} default = "My
"We favorite
love pets!"
pet is Mrs. Whiskers"
}
resource "random_pet" "my-pet" { variable "prefix" {
prefix = var.prefix
"Mrs" default = "Mrs"
separator = var.separator
"." }
length = var.length
"1" variable "separator" {
} default = "."
}
variable "length" {
default = "1"
"2"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
Terraform will perform the following actions:

-/+ resource "local_file" "pet" {


~ content = “We love pets!" -> "My favorite pet is Mrs. Whiskers!" #
forces replacement
directory_permission = "0777"
file_permission = "0777"
filename = "/root/pet.txt"
~ id = "bc9cabef1d8b0071d3c4ae9959a9c328f35fe697" -> (known after
apply)
}

# random_pet.my-pet must be replaced


-/+ resource "random_pet" "my-pet" {
~ id = "Mrs.Hen" -> (known after apply)
~ length = 1 -> 2 # forces replacement
prefix = "Mrs"
separator = "."
}

Plan: 2 to add, 0 to change, 2 to destroy.


random_pet.my-pet: Destroying... [id=Mrs.hen]
random_pet.my-pet: Destruction complete after 0s
local_file.pet: Destroying... [id=bc9cabef1d8b0071d3c4ae9959a9c328f35fe697]
local_file.pet: Destruction complete after 0s
random_pet.my-pet: Creating...
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet: Creating...
main.tf variables.tf
resource "aws_instance" "webserver" { variable "ami" {
ami = var.ami
var.ami default = "ami-0edab43b6fa892279"
instance_type = var.instance_type
var.instance_type }
} variable "instance_type" {
default = "t2.micro"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Understanding the
Variable Block
variables.tf
variable "filename" {
default = "/root/pets.txt"
}
variable "content" {
default = "I love pets!"
}
variable "prefix" {
default = "Mrs"
}
variable "separator" {
default = "."
}
variable "length" {
default = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
variable "filename" {
default = "/root/pets.txt"
type = string
description = "the path of local file"

}
variable "content" {
default = "I love pets!"
type = string
description = “the content of the file"

}
variable "prefix" {
default = "Mrs"
type = string
description = "the prefix to be set"

}
variable "separator" {
default = "."
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf Type Example

variable "filename" { string "/root/pets.txt"


default = "/root/pets.txt"
type = string number 1
description = "the path of local file"
bool true/false

} any Default Value


variable "content" {
default = "I love pets!"
variables.tf
type = string
description = “the content of the file"
variable "length" {
} default = 2
variable "prefix" { type = number
default = "Mrs" description = "length of the pet name"
type = string }
description = "the prefix to be set"

} variable "password_change" {
variable "separator" { default = true
default = "." type = bool
© Copyright KodeKloud } course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full
Type Example

string "/root/pets.txt"

number 1

bool true/false

any Default Value

list ["cat", "dog"]

pet1 = cat
map
pet2 = dog

Complex Data
object
Structure

Complex Data
tuple
Structure

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
List
variables.tf maint.tf

variable "prefix" { resource "random_pet" "my-pet" {


default = ["Mr", "Mrs", "Sir"] prefix = var.prefix[0]
type = list 0 1 2 }
}

Index Value

0 Mr

1 Mrs

2 Sir

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Map

variables.tf maint.tf

variable file-content { resource local_file my-pet {


type = map filename = "/root/pets.txt"
default = { content = var.file-content["statement2"]
"statement1" = "We love pets!" }
"statement2" = “We love animals!"
}
}

Key Value

statement1 We love pets!

statement2 We love animals!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
List of a Type

variables.tf variables.tf

variable "prefix" { variable "prefix" {


default = ["Mr", "Mrs", "Sir"] default = ["Mr", "Mrs", "Sir"]
type = list(string) type = list(number)
} }

variables.tf >_
$ terraform plan
variable "prefix" { Error: Invalid default value for variable

default = [1, 2, 3] on variables.tf line 3, in variable "prefix":


type = list(number) 3: default = ["Mr", "Mrs", "Sir"]
}
This default value is not compatible with the
variable's type constraint: a number is required.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Map of a Type

variables.tf variables.tf
variable "cats" { variable "pet_count" {
default = { default = {
"color" = "brown" "dogs" = 3
"name" = "bella" "cats" = 1
} "goldfish" = 2
type = map(string) }
} type = map(number)
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Set

variables.tf variables.tf
variable "prefix" { variable "prefix" {
default = ["Mr", "Mrs", "Sir"] default = ["Mr", "Mrs", "Sir", "Sir"]
type = set(string) type = set(string)
} }

variables.tf variables.tf
variable "fruit" { variable "fruit" {
default = ["apple", "banana"] default = ["apple", "banana", "banana"]
type = set(string) type = set(string)
} }

variables.tf variables.tf
variable "age" { variable "age" {
default = [10, 12, 15] default = [10, 12, 15, 10]
type = set(number) type = set(number)
} KodeKloud
© Copyright } full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our
Objects
Key Example Type
variables.tf
name bella string
variable "bella" {
color brown string type = object({
name = string
age 7 number color = string
age = number
food ["fish", "chicken", "turkey"] list
food = list(string)
favorite_pet true bool
favorite_pet = bool
})

default = {
name = "bella"
color = "brown"
age = 7
food = ["fish", "chicken", "turkey"]
favorite_pet = true
}
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tuples
variables.tf
variable kitty {
type = tuple([string, number, bool])
default = ["cat", 7, true]

variables.tf >_
$ terraform plan
variable kitty { Error: Invalid default value for variable
type = tuple([string, number, bool])
default = ["cat", 7, true, "dog"] on variables.tf line 3, in variable "kitty":
3: default = ["cat", 7, true, "dog"]
} This default value is not compatible with the
variable's type constraint:
tuple required.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Using Variables in
Terraform
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename
"/root/pets.txt" default = "/root/pets.txt"
var.content
content = "We love pets!" }
variable "content" {
} default = "We love pets!"
}
resource "random_pet" "my-pet" { variable "prefix" {
prefix = var.prefix
"Mrs" default = "Mrs"
separator = var.separator
"." }
length = var.length
"1" variable "separator" {
} default = "."
}
variable "length" {
default = 2
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename
"/root/pets.txt"
var.content
content = "We love pets!" }
variable "content" {
}
}
resource "random_pet" "my-pet" { variable "prefix" {
prefix = var.prefix
"Mrs"
separator = var.separator
"." }
length = var.length
"1" variable "separator" {
}
}
variable "length" {

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Interactive Mode

>_
$ terraform apply
var.content
Enter a value: We love Pets!

var.filename
Enter a value: /root/pets.txt

var.length
Enter a value: 2

var.prefix
Enter a value: Mrs.

var.separator
Enter a value: .

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Command Line Flags

>_

$ terraform apply -var "filename=/root/pets.txt" -var "content=We love


Pets!" -var "prefix=Mrs" -var "separator=." -var "length=2"

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Environment Variables

>_

$ export TF_VAR_filename="/root/pets.txt"
$ export TF_VAR_content="We love pets!"
$ export TF_VAR_prefix="Mrs"
$ export TF_VAR_separator="."
$ export TF_VAR_length="2"
$ terraform apply

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Files

terraform.tfvars
filename = "/root/pets.txt"
content = "We love pets!"
prefix = "Mrs"
separator = "."
length = "2"

>_

$ terraform apply -var-file variables.tfvars

terraform.tfvars | terraform.tfvars.json
Automatically Loaded
*.auto.tfvars | *.auto.tfvars.json

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Precedence

main.tf >_
resource local_file pet {
$ export TF_VAR_filename="/root/cats.txt" ?
filename = var.filename
}
terraform.tfvars
variables.tf
filename = "/root/pets.txt" ?
variable filename {
type = string
} variable.auto.tfvars
filename = "/root/mypet.txt" ?

>_

$ terraform apply -var "filename=/root/best-pet.txt" ?

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Variable Definition Precedence

Order Option >_


1 Environment Variables $ export TF_VAR_filename="/root/cats.txt" 1?
2 terraform.tfvars

3 *.auto.tfvars (alphabetical order) terraform.tfvars


filename = "/root/pets.txt" 2?
4 -var or –var-file (command-line flags)

variable.auto.tfvars
filename = "/root/mypet.txt" 3?

>_

$ terraform apply -var "filename=/root/best-pet.txt" 4?

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource Attribute
Reference
FILENAME CONTENT PREFIX SEPERATOR

main.tf
LENGTH
resource "local_file" "pet" {
filename = var.filename
content = "My favorite pet is Mr.Cat"
}

resource "random_pet" "my-pet" {


prefix = var.prefix Mr.Bull
separator = var.separator
length = var.length
}

>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
FILENAME CONTENT PREFIX SEPERATOR

main.tf
LENGTH
resource "local_file" "pet" {
filename = var.filename
content = "My favorite pet is Mr.Cat"
}

resource "random_pet" "my-pet" {


prefix = var.prefix Mr.Bull
separator = var.separator
length = var.length
}

>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
FILENAME CONTENT PREFIX SEPERATOR

main.tf
resource "local_file" "pet" {
filename = var.filename
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat"
}

resource "random_pet" "my-pet" {


prefix = var.prefix Mr.Bull
separator = var.separator
length = var.length
}

>_
random_pet.my-pet: Creating...
local_file.pet: Creating...
random_pet.my-pet: Creation complete after 0s [id=Mr.bull]
local_file.pet: Creation complete after 0s
[id=059090e865809f9b6debfda7aebf48fdce2220a6]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.


© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
l_file" "pet" {
var.filename

"My favorite pet is ${random_pet.my-pet.id}"


Mr.Cat"
Mr.Bull"

om_pet" "my-pet" {
r.prefix
var.separator
r.length
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
.
.
.
# local_file.pet must be replaced
-/+ resource "local_file" "pet" {
~ content = "My favorite pet is Mrs.Cat!" ->
"My favorite pet is Mr.bull" # forces replacement
directory_permission = "0777"
file_permission = "0777"
filename = "/roots/pets.txt"
~ id =
"98af5244e23508cffd4a0c3c46546821c4ccbbd0" -> (known after
apply)
}
.
.
local_file.pet: Destroying...
[id=98af5244e23508cffd4a0c3c46546821c4ccbbd0]
local_file.pet: Destruction complete after 0s
local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=e56101d304de7cf1b1001102923c6bdeaa60c523]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Resource
Dependencies
Implicit Dependency

main.tf
resource "local_file" "pet" {
filename = var.filename 2 1
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat"
}

resource "random_pet" "my-pet" {


prefix = var.prefix
separator = var.separator
length = var.length
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Explicit Dependency

main.tf
resource "local_file" "pet" {
filename = var.filename 2 1
content = "My favorite pet is Mr.Cat"
depends_on = [
random_pet.my-pet
]

resource "random_pet" "my-pet" {


prefix = var.prefix
separator = var.separator
length = var.length
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Output Variables
main.tf variables.tf
resource "local_file" "pet" { variable "filename" {
filename = var.filename default = "/root/pets.txt"
${random_pet.my-pet.id}"
content = "My favorite pet is Mr.Cat" }
} variable "content" {
default = "I love pets!"
resource "random_pet" "my-pet" { }
prefix = var.prefix variable "prefix" {
separator = var.separator default = "Mrs"
length = var.length }
} variable "separator" {
default = "."
output pet-name { }
value = random_pet.my-pet.id variable "length" {
description = "Record the value of pet ID generated by the default = "1"
random_pet resource" }
}

output "<variable_name>" {
value = "<variable_value>"
<arguments>
}
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform apply
.
.

Outputs:

pet-name = Mrs.gibbon

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_
$ terraform output
pet-name = Mrs.gibbon

>_
$ terraform output pet-name
Mrs.gibbon

Output Variable

SHELL SCRIPTS
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Introduction to
Terraform State
>_ >_
$ cd terraform-local-file
$ ls terraform-local-file [terraform-local-file]$ terraform init
main.tf variables.tf
Initializing the backend...

Initializing provider plugins...


main.tf - Finding latest version of hashicorp/local...
- Installing hashicorp/local v1.4.0...
- Installed hashicorp/local v1.4.0 (signed by HashiCorp)
resource "local_file" "pet" {
The following providers do not have any version constraints
filename = var.filename in configuration,
content = var.content so the latest version was installed.
} Init
To prevent automatic upgrades to new major versions that
may contain breaking
variables.tf changes, we recommend adding version constraints in a
required_providers block
in your configuration, with the constraint strings
variable "filename" { suggested below.
default = "/root/pets.txt"
* hashicorp/local: version = "~> 1.4.0"
}
variable "content" { Terraform has been successfully initialized!

default = "I love pets!"


}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_
[terraform-local-file]$ terraform plan
$ ls terraform-local-file
Refreshing Terraform state in-memory prior to plan...
main.tf variables.tf
The refreshed state will be used to calculate this plan,
persisted to local or remote state storage.
main.tf
--------------------------------------------------------
resource "local_file" "pet" {
filename = var.filename An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbol
content = var.content + create
} Plan
Init
Terraform will perform the following actions:
variables.tf
# local_file.pet will be created
variable "filename" { + resource "local_file" "pet" {
+ content = "I love pets!"
default = "/root/pets.txt" + directory_permission = "0777"
} + file_permission = "0777"
variable "content" { + filename = "/root/pets.txt"
+ id = (known after apply)
default = "I love pets!" }
}
Plan: 1 to add, 0 to change, 0 to destroy.

--------------------------------------------------------
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Note: You didn't specify an "-out" parameter to save thi
>_ >_
[terraform-local-file]$ terraform apply
$ ls terraform-local-file
An execution plan has been generated and is shown below.
main.tf variables.tf
Resource actions are indicated with the following symbol
+ create
main.tf Terraform will perform the following actions:

resource "local_file" "pet" { # local_file.pet will be created


filename = var.filename + resource "local_file" "pet" {
+ content = "I love pets!"
content = var.content + directory_permission = "0777"
} Apply
Plan
Init + file_permission = "0777"
+ filename = "/root/pets.txt"
variables.tf + id = (known after apply)
}
variable "filename" {
Plan: 1 to add, 0 to change, 0 to destroy.
default = "/root/pets.txt"
} Do you want to perform these actions?
variable "content" { Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
default = "I love pets!"
} Enter a value: yes

local_file.pet: Creating...
local_file.pet: Creation complete after 0s
© Copyright KodeKloud [id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_

[terraform-local-file]$ cat /root/pets [terraform-local-file]$ terraform apply


local_file.pet: Refreshing state...
I love pets!
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]

Apply complete! Resources: 0 added, 0 changed, 0 destro

Apply
Plan
Init

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
>_ >_

[terraform-local-file]$ ls [terraform-local-file]$ cat terraform.tfstate


{
main.tf variables.tf terraform.tfstate
"version": 4,
"terraform_version": "0.13.0",
"serial": 1,
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31"
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
Apply
Plan
Init "name": "pet",
"provider":
"provider[\"registry.terraform.io/hashicorp/local\"
"instances": [
{
"schema_version": 0,
"attributes": {
"content": "I love pets!",
"content_base64": null,
"directory_permission": "0777",
"file_permission": "0777",
"filename": "/root/pets.txt",
"id":
"7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68",
"sensitive_content": null
© Copyright KodeKloud Check out our full course on},
Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
"private": "bnVsbA=="
>_
variables.tf
[terraform-local-file]$ cat terraform.tfstate
variable "filename" { {
default = "/root/pets.txt" "version": 4,
} "terraform_version": "0.13.0",
"serial": 1,
variable "content" {
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31"
default = "We
"I love
love pets!"
pets!" "outputs": {},
} "resources": [
{
"mode": "managed",
"type": "local_file",
>_ Apply
Plan
Init "name": "pet",
"provider":
$ terraform plan "provider[\"registry.terraform.io/hashicorp/local\"
Refreshing Terraform state in-memory "instances": [
prior to plan... {
The refreshed state will be used to "schema_version": 0,
calculate this plan, but will not be "attributes": {
persisted to local or remote state "content": "I love pets!",
storage. "content_base64": null,
"directory_permission": "0777",
local_file.pet: Refreshing state... "file_permission": "0777",
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e "filename": "/root/pets.txt",
1b68] "id":
. "7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68",
. "sensitive_content": null
. Copyright KodeKloud
© Check out our full course on},
Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
[Output Truncated ] "private": "bnVsbA=="
>_
variables.tf
[terraform-local-file]$ cat terraform.tfstate
variable "filename" { {
default = "/root/pets.txt" "version": 4,
} "terraform_version": "0.13.0",
"serial": 1,
variable "content" {
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31"
default = "We
"I love
love pets!"
pets!" "outputs": {},
} "resources": [
{
"mode": "managed",
"type": "local_file",
>_ Apply
Plan
Init "name": "pet",
"provider":
$ terraform apply "provider[\"registry.terraform.io/hashicorp/local\"
local_file.pet: Refreshing state... "instances": [
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68] {
"schema_version": 0,
Terraform will perform the following actions:
"attributes": {
# local_file.pet must be replaced "content": "We "I lovelovepets!",
pets!“,
-/+ resource "local_file" "pet" { "content_base64": null,
~ content = "I love pets!" - "directory_permission": "0777",
> "We love pets!" # forces replacement "file_permission": "0777",
directory_permission = "0777" "filename": "/root/pets.txt",
file_permission = "0777"
"id":
filename = "/root/pets.txt"
~ id = "7e4db4fbfdbb108bdd04692602bae3e9bc4d1c14",
"7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68" -> "sensitive_content": null
(known
© after
Copyright apply)
KodeKloud Check out our full course on},
Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
} "private": "bnVsbA=="
Real World Infrastructure terraform.tfstate

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Purpose of State
Real World Infrastructure terraform.tfstate

id=aabbcc id=eeddff id=gghhhii

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata

pet
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "My favorite pet is ${random_pet.my-pet.id}!"
}
resource "random_pet" "my-pet" {
length = 1 my-pet
}
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}

cat

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata
>_
$ terraform apply pet

.
.
.
Plan: 3 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above. my-pet
Only 'yes' will be accepted to approve.

Enter a value: yes

local_file.cat: Creating...
random_pet.my-pet: Creating...
local_file.cat: Creation complete after 0s
[id=fe448888891fc40342313bc44a1f1a8986520c89]
random_pet.my-pet: Creation complete after 0s [id=yak] cat

local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=28b373c6c1fa3fce132a518eadd0175c98f37f20]

Apply complete! Resources: 3 added, 0 changed, 0


destroyed.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata

pet
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "My favorite pet is ${random_pet.my-pet.id}!"
}
resource "random_pet" "my-pet" {
length = 1 my-pet
}
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}

cat

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata

pet
main.tf

my-pet

resource "local_file" "cat" {


filename = "/root/cat.txt"
content = "I like cats too!"
}

cat

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Tracking Metadata

pet
main.tf
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}

my-pet
>_
$ cat terraform.tfstate
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [ cat
{
"schema_version": 0,
"attributes": {
"content": "My favorite pet is yak!",
. },
"private": "bnVsbA==",
"dependencies": [
"random_pet.my-pet"
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
]
Tracking Metadata

pet
main.tf
resource "local_file" "cat" {
filename = "/root/cat.txt"
content = "I like cats too!"
}

my-pet
>_
$ terraform apply
Plan: 0 to add, 0 to change, 2 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above.
Only 'yes' will be accepted to approve. cat

Enter a value: yes

local_file.pet: Destroying...
[id=28b373c6c1fa3fce132a518eadd0175c98f37f20]
local_file.pet: Destruction complete after 0s

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
random_pet.my-pet: Destroying... [id=yak]
Performance

terraform.tfstate

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Performance

terraform.tfstate >_
{ $ terraform plan --refresh=false
"version": 4, An execution plan has been generated and is shown
"terraform_version": "0.13.0", below.
"serial": 4, Resource actions are indicated with the following
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31", symbols:
"outputs": {}, -/+ destroy and then create replacement
"resources": [
{ Terraform will perform the following actions:
"mode": "managed",
"type": "local_file", # local_file.cat must be replaced
"name": "pet", -/+ resource "local_file" "pet" {
"instances": [ ~ content = "I like cats too!" ->
{ "Dogs are awesome!" # forces replacement
"schema_version": 0, directory_permission = "0777"
"attributes": { file_permission = "0777"
"content": "We love pets!", filename = "/root/pets.txt"
"content_base64": null, ~ id =
"directory_permission": "0777", "cba595b7d9f94ba1107a46f3f731912d95fb3d2c" -> (known
... after apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.


© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
------------------------------------------------------
Collaboration

terraform.tfstate >_
{ $ ls
"version": 4,
"terraform_version": "0.13.0", main.tf variables.tf terraform.tfstate
"serial": 4,
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [
{
"schema_version": 0, terraform.tfstate
"attributes": {
"content": "We love pets!",
"content_base64": null,
"directory_permission": "0777",
...

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
AWS S3 HashiCorp Consul
Collaboration Google Cloud Storage Terraform Cloud

terraform.tfstate
{
"version": 4,
"terraform_version": "0.13.0",
"serial": 4, terraform.tfstate
"lineage": "e35dde72-a943-de50-3c8b-1df8986e5a31",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
"name": "pet",
"instances": [
{
"schema_version": 0,
"attributes": {
"content": "We love pets!",
"content_base64": null,
"directory_permission": "0777",
...

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State
Considerations
Sensitive Data

terraform.tfstate
{
"mode": "managed",
"type": "aws_instance",
"name": "dev-ec2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"ami": "ami-0a634ae95e11c6f91",
.
.
.
"primary_network_interface_id": "eni-0ccd57b1597e633e0",
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
© Copyright KodeKloud "iops": 100, Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform State Considerations
Remote State Backends Version
Control

terraform.tfstate main.tf
{ resource "local_file" "pet" {
"mode": "managed",
filename = "/root/pet.txt"
"type": "aws_instance",
"name": "dev-ec2", content = "My favorite pet is Mr.Whiskers!"
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", }
"instances": [ resource "random_pet" "my-pet" {
{
"schema_version": 1,
length = 1
"attributes": { }
"ami": "ami-0a634ae95e11c6f91", resource "local_file" "cat" {
. filename = "/root/cat.txt"
.
. content = "I like cats too!"
"primary_network_interface_id": "eni-0ccd57b1597e633e0", }
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
"iops": 100,
"kms_key_id": "",
© Copyright K odeK"volume_id":
l oud "vol-070720a3636979c22", Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
No Manual Edits

terraform.tfstate
{
"mode": "managed",
"type": "aws_instance",
"name": "dev-ec2",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"ami": "ami-0a634ae95e11c6f91",
.
.
.
"primary_network_interface_id": "eni-0ccd57b1597e633e0",
"private_dns": "ip-172-31-7-21.us-west-2.compute.internal",
"private_ip": "172.31.7.21",
"public_dns": "ec2-54-71-34-19.us-west-2.compute.amazonaws.com",
"public_ip": "54.71.34.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/sda1",
"encrypted": false,
© Copyright KodeKloud "iops": 100, Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Terraform Commands
terraform validate

main.tf >_

resource "local_file" "pet" { $ terraform validate


filename = "/root/pets.txt" Success! The configuration is valid.
content = "We love pets!"
file_permissions = "0700"
} $ terraform validate

Error: Unsupported argument

on main.tf line 4, in resource "local_file" "pet":


4: file_permissions = "0777"

An argument named "file_permissions" is not expected


here. Did you mean "file_permission"?

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform fmt

main.tf >_

resource "local_file" "pet" { $ terraform fmt


filename = "/root/pets.txt"
main.tf
content = "We love pets!"
file_permission = "0700"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform fmt

main.tf >_

resource "local_file" "pet" { $ terraform fmt


filename = "/root/pets.txt"
main.tf
content = "We love pets!"
file_permission = "0700"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform show

>_ >_

$ terraform show $ terraform show -json


# local_file.pet: {"format_version":"0.1","terraform_version":"0.13.0
resource "local_file" "pet" { ","values":{"root_module":{"resources":[{"address":
content = "We love pets!" "local_file.pet","mode":"managed","type":"local_fil
directory_permission = "0777" e","name":"pet","provider_name":"registry.terraform
file_permission = "0777" .io/hashicorp/local","schema_version":0,"values":{"
filename = "/root/pets.txt" content":"We love
id = pets!","content_base64":null,"directory_permission"
"cba595b7d9f94ba1107a46f3f731912d95fb3d2c" :"0777","file_permission":"0777","filename":"/root/
} pets.txt","id":"cba595b7d9f94ba1107a46f3f731912d95f
b3d2c","sensitive_content":null}}]}}}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform providers
main.tf >_

resource "local_file" "pet" { $ terraform providers


filename = "/root/pets.txt" Providers required by configuration:
content = "We love pets!" .
file_permission = "0700" └── provider[registry.terraform.io/hashicorp/local]
}
Providers required by state:

provider[registry.terraform.io/hashicorp/local]

$ terraform providers mirror /root/terraform/new_local_file


- Mirroring hashicorp/local...
- Selected v1.4.0 with no constraints
- Downloading package for windows_amd64...
- Package authenticated: signed by HashiCorp

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform output
main.tf >_

resource "local_file" "pet" { $ terraform output


filename = "/root/pets.txt"
content = "We love pets!" content = We love pets!
file_permission = "0777" pet-name = huge-owl
}
resource "random_pet" "cat" {
length = "2"
separator = "-"
} $ terraform output pet-name
output content {
value = local_file.pet.content pet-name = huge-owl
sensitive = false
description = "Print the content of the file"

}
output pet-name {
value = random_pet.cat.id
sensitive = false
description = "Print the name of the pet"

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform refresh
main.tf >_

resource "local_file" "pet" { $ terraform refresh


filename = "/root/pets.txt"
random_pet.cat: Refreshing state... [id=huge-owl]
content = "We love pets!"
local_file.pet: Refreshing state...
file_permission = "0777"
[id=cba595b7d9f94ba1107a46f3f731912d95fb3d2c]
}
resource "random_pet" "cat" {
length = "2"
separator = "-"
} $ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this
plan, but will not be
persisted to local or remote state storage.

random_pet.cat: Refreshing state... [id=huge-owl]


local_file.pet: Refreshing state...
[id=cba595b7d9f94ba1107a46f3f731912d95fb3d2c]
------------------------------------------------------

No changes. Infrastructure is up-to-date.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform graph
main.tf >_

resource "local_file" "pet" { $ terraform graph


filename = "/root/pets.txt" digraph {
content = "My favorite pet is ${random_pet.m compound = "true"
y-pet.id}" newrank = "true"
} subgraph "root" {
resource "random_pet" "my-pet" { "[root] local_file.pet (expand)" [label =
prefix = "Mr" "local_file.pet", shape = "box"]
separator = "." "[root]
length = "1" provider[\"registry.terraform.io/hashicorp/local\"]" [label =
} "provider[\"registry.terraform.io/hashicorp/local\"]", shape =
"diamond"]
"[root]
provider[\"registry.terraform.io/hashicorp/random\"]" [label =
"provider[\"registry.terraform.io/hashicorp/random\"]", shape =
"diamond"]
"[root] random_pet.my-pet (expand)" [label =
"random_pet.my-pet", shape = "box"]
"[root] local_file.pet (expand)" -> "[root]
provider[\"registry.terraform.io/hashicorp/local\"]"
"[root] local_file.pet (expand)" -> "[root]
random_pet.my-pet (expand)"
"[root] meta.count-boundary (EachMode fixup)" -
> "[root] local_file.pet (expand)"
"[root]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
provider[\"registry.terraform.io/hashicorp/local\"] (close)" ->
terraform graph
main.tf >_

resource "local_file" "pet" { $ apt update


filename = "/root/pets.txt"
$ apt install graphviz -y
content = "My favorite pet is ${random_pet.m
y-pet.id}" $ terraform graph | dot -Tsvg > graph.svg
}
resource "random_pet" "my-pet" {
prefix = "Mr"
separator = "."
length = "1"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Mutable vs
Immutable
Infrastructure
terraform validate

main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet: Destruction complete after 0s
v1.19
v1.18
upgrade-nginx.sh
v1.17

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Mutable Infrastructure

v1.19 v1.19 v1.19


v1.18 v1.18 v1.18
v1.17 v1.17 v1.17

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Configuration Drift

v1.19 v1.19
v1.18 v1.18 v1.18
v1.17 v1.17 v1.17

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
v1.17 v1.17 v1.17

1 2 3

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4
v1.17 v1.17 v1.17 v1.18

1 2 3

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4 5
v1.17 v1.17 v1.18 v1.18

2 3

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
4 5 6
v1.17 v1.18 v1.18 v1.18

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure

4 5 6
v1.18 v1.18 v1.18

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure

4 5
v1.17 v1.18 v1.18

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Immutable Infrastructure
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.

local_file.pet:
local_file.pet: Destroying...
Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet:
local_file.pet: Destruction
Destruction complete
complete after
after 0s
0s
local_file.pet: Creating...
local_file.pet: Creating...
local_file.pet:
local_file.pet: Creation
Creation complete
complete after
after 0s
0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Lifecycle Rules
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
content = "We love pets!" -/+ resource "local_file" "pet" {
content = "We love pets!"
file_permission = "0700"
directory_permission = "0777"
}
~ file_permission = "0777" -> "0700" # forces
replacement
filename = "/root/pet.txt"
~ id =
"5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after
apply)
}

Plan: 1 to add, 0 to change, 1 to destroy.

local_file.pet:
local_file.pet: Destroying...
Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet:
local_file.pet: Destruction
Destruction complete
complete after
after 0s
0s
local_file.pet: Creating...
local_file.pet: Creating...
local_file.pet:
local_file.pet: Creation
Creation complete
complete after
after 0s
0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
create_before_destroy
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" # local_file.pet must be replaced
-/+ resource "local_file" "pet" {
content = "We love pets!"
content = "We love pets!"
file_permission = "0700" directory_permission = "0777"
~ file_permission = "0777" -> "0755" # forces repl
lifecycle { filename = "/root/pet.txt"
create_before_destroy = true ~ id =
} "5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf" -> (known after ap
}

} Plan: 1 to add, 0 to change, 1 to destroy.

...

local_file.pet: Creating...
local_file.pet: Creation complete after 0s
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]

local_file.pet: Destroying...
[id=5f8fb950ac60f7f23ef968097cda0a1fd3c11bdf]
local_file.pet: Destruction complete after 0s

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
prevent_destroy
main.tf >_
$ terraform apply
resource "local_file" "pet" {
filename = "/root/pets.txt" local_file.my-pet: Refreshing state...
content = "We love pets!" [id=cba595b7d9f94ba1107a46f3f731912d95fb3d2c]
file_permission = "0700"
Error: Instance cannot be destroyed
lifecycle {
create_before_destroy
prevent_destroy = true= true on main.tf line 1:
} 1: resource "local_file" "my-pet" {

Resource local_file.my-pet has


} lifecycle.prevent_destroy set, but the plan calls
for this resource to be destroyed. To avoid this error
and continue with the plan, either disable
lifecycle.prevent_destroy or reduce the scope of the
plan using the -target flag.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
instance_type = "t2.micro" ...
Terraform will perform the following actions:
tags = {
Name = “ProjectA-Webserver"
# aws_instance.webserver will be created
}
+ resource "aws_instance" "webserver" {
}
+ ami = "ami-0edab43b6fa892279"
+ get_password_data = false
+ host_id = (known after apply)
+ id = (known after apply)
+ instance_state = (known after apply)
+ instance_type = "t2.micro“
+ tags {
+ "Name" = "ProjectA-WebServer"
}
.
aws_instance.webserver: Creation complete after 33s [id=i-
05cd83b221911acd5]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279" aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro" 05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver" An execution plan has been generated and is shown below.
} Resource actions are indicated with the following symbols:
} ~ update in-place

Terraform will perform the following actions:

# aws_instance.webserver will be updated in-place


~ resource "aws_instance" "webserver" {
.
.
~ tags = {
~ "Name" = "ProjectB-WebServer" -> "ProjectA-WebServer"
}
.
.
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro"
05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver"
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
}
lifecycle {
ignore_changes = [
tags

]
}
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
ignore_changes
main.tf >_
resource "aws_instance" "webserver" { $ terraform apply
ami = "ami-0edab43b6fa892279"
aws_instance.webserver: Refreshing state... [id=i-
instance_type = "t2.micro"
05cd83b221911acd5]
tags = {
Name = “ProjectA-Webserver"
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
}
lifecycle {
ignore_changes == all
ignore_changes [
tags,ami

]
}
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Order Option

Create the resource first and


1 create_before_destroy
then destroy older

2 prevent_destroy Prevents destroy of a resource

Ignore Changes to Resource


3 ignore_changes
Attributes (specific/all)

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright K odeK l oud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Data Sources
Real World Infrastructure terraform.tfstate

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = "We love pets!"
}

>_
$ cat /root/dog.txt
Dogs are awesome!

Real World Infrastructure terraform.tfstate

dogs.txt pets.txt

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Data Sources main.tf

resource "local_file" "pet" {


filename = "/root/pets.txt"
content = data.local_file.dog.content
"We love pets!"
}

>_ data "local_file" "dog" {


filename = "/root/dog.txt"
$ cat /root/dog.txt
}
Dogs are awesome!

Real World Infrastructure terraform.tfstate

dogs.txt pets.txt

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
terraform.tfstate

Resource Data Source

Keyword: resource Keyword: data

Creates, Updates, Destroys


Only Reads Infrastructure
Infrastructure

Also called Managed Resources Also called Data Resources

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Meta Arguments
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename default = "/root/pets.txt"
content = var.content }
variable "content" {
} default = "I love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Shell Scripts
create_files.sh >_

#!/bin/bash $ ls -ltr /root/


-rw-r--r-- 1 root root 0 Sep 9 02:04 pet2
for i in {1..3} -rw-r--r-- 1 root root 0 Sep 9 02:04 pet1
do -rw-r--r-- 1 root root 0 Sep 9 02:04 pet3

touch /root/pet${i}
done

Iteration filename

1 /root/pet1

2 /root/pet2

3 /root/pet3
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Meta Arguments
depends_on lifecycle

main.tf main.tf

resource "local_file" "pet" {


filename = var.filename
content = var.content resource "local_file" "pet" {
depends_on = [ filename = "/root/pets.txt"
random_pet.my-pet content = "We love pets!"
] file_permission = "0700
} lifecycle {
resource "random_pet" "my-pet" { create_before_destroy = true
prefix = var.prefix }
separator = var.separator }
length = var.length
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Count
count

main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename default = "/root/pets.txt"
}
count = 3
} >_
$ terraform plan
[Output Truncated]
Terraform will perform the following actions:
...
# local_file.pet[2] will be created
+ resource "local_file" "pet" {
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pets.txt"
+ id = (known after apply)
}

Plan: 3 to add, 0 to change, 0 to destroy.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
count

main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename default = "/root/pets.txt"
}
count = 3
} >_
$ terraform
$ ls /rootapply
pet.txt
[Output Truncated]
.

local_file.pet[2]: Creating...
pet[1] local_file.pet[0]: Creating...
pet[0] pet[2]
local_file.pet[1]: Creating...
local_file.pet[0]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
local_file.pet[2]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]
local_file.pet[1]: Creation complete after 0s
[id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]

© Copyright KodeKloud Check outcomplete!


Apply our full course on Terraform for the3Absolute
Resources: added, Beginners: https://kode.wiki/3PoScZd
0 changed, 0
count

main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename [count.index] default
default == "/root/pets.txt"
[
count = 3 "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]

>_
pet[0] pet[1] pet[2]
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
cats.txt
local_file.pet[2]: Creating...
local_file.pet[0]: Creating...
local_file.pet[1]: Creating...
© Copyright KodeKloud local_file.pet[0]: Creation
Check out our full course on Terraform complete
for the Absolute after
Beginners: 0s
https://kode.wiki/3PoScZd
Length Function

main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename [count.index] default
default == "/root/pets.txt"
[
count = length(var.filename)
3 "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt",
"/root/cows.txt",
"/root/ducks.txt"
]

}
pet[0] pet[1] pet[2]

>_
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
© Copyright KodeKloud cats.txt
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet[2]: Creating...
Length Function

variable function value

fruits = [ "apple", "banana", "orange"] length(fruits) 3

cars = [ “honda”, “bmw”, “nissan”, “kia”] length(cars) 4

colors = [ “red”, “purple”] length(colors) 2

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
LengthFunction

main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename [count.index] default
default == "/root/pets.txt"
[
count = length(var.filename)
3 "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt",
"/root/cows.txt",
"/root/ducks.txt"
]

}
pet[0] pet[1] pet[2]

>_
$ ls /rootapply
$ terraform
pet.txt
pets.txtTruncated]
[Output
.dogs.txt
© Copyright KodeKloud cats.txt
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
local_file.pet[2]: Creating...
>_ >_
$ terraform apply $ ls /root
. pet.txt
. dogs.txt
Terraform will perform the following actions: cats.txt

# local_file.pet[0] will be created


+ resource "local_file" "pet" {
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/pets.txt"
+ id = (known after apply)
}

# local_file.pet[1] will be created


+ resource "local_file" "pet" {
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/dogs.txt"
+ id = (known after apply)
}

# local_file.pet[2] will be created


+ resource "local_file" "pet" {
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "/root/cats.txt"
+ idKodeKloud
© Copyright = (known after apply) Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf variables.tf

resource "local_file" "pet" { variable "filename" {


filename = var.filename [count.index] default
default == "/root/pets.txt"
[
count = length(var.filename)
3 "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]

pet[0] pet[1] pet[2]

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
variable "filename" {
default
default == "/root/pets.txt"
[
main.tf
"/root/pets.txt",
"/root/dogs.txt",
resource "local_file" "pet" { "/root/cats.txt"
filename = var.filename [count.index] ]

count = length(var.filename)
3 }
}
>_
$ terraform plan
...
# local_file.pet[0] must be replaced
-/+ resource "local_file" "pet" {
directory_permission = "0777"
file_permission = "0777"
pet[0] pet[1] pet[2] ~ filename = "/root/pets.txt" -> "/root/dogs.txt" #
forces replacement
}
# local_file.pet[1] must be replaced
-/+ resource "local_file" "pet" {
directory_permission = "0777"
file_permission = "0777"
~ filename = "/root/dogs.txt" -> "/root/cats.txt" #
forces replacement
}
# local_file.pet[2] will be destroyed
Replace
© Copyright KodeKloud Replace Destroy - resource "local_file" "pet" {
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
- directory_permission = "0777" -> null
main.tf >_
$ terraform output
resource "local_file" "pet" { Outputs:
filename = var.filename [count.index] pets = [
{
count = length(var.filename)
3 "directory_permission" = "0777"
} "file_permission" = "0777"
"filename" = "/root/pets.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
output "pets" { },
value = local_file.pet {
} "directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/dogs.txt"
pet[0] pet[1] pet[2] "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
{
"directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
]
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
pet[0] pet[1] pet[2] variable "filename" {
default
default == "/root/pets.txt"
[
"/root/pets.txt",
"/root/dogs.txt",
"/root/cats.txt"
]

pets.txt dogs.txt cats.txt }

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
variables.tf
pet[0] pet[1] variable "filename" {
default
default == "/root/pets.txt"
[
"/root/pets.txt",
"/root/dogs.txt",
"/root/cats.txt"
]

dogs.txt cats.txt }

Resource Resource Updates Action

pet[0] /root/pets.txt" -> "/root/dogs.txt" Destroy and Replace

pet[1] "/root/dogs.txt" -> "/root/cats.txt" Destroy and Replace

© Copyrightpet[2]
KodeKloud Does not Exist Check out our full course onDestroy
Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
for_each
for_each

main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
3var.filename "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]

>_
pet[0] pet[1] pet[2]
$ terraform plan
Error: Invalid for_each argument

on main.tf line 2, in resource "local_file" "pet":


2: for_each = var.filename

The given "for_each" argument value is unsuitable: the "for_each"


argument must be a map, or set of strings, and you have provided a value
of type list of string.
© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each

main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
type=set(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
3var.filename "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]

>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform
Error: Invalid
will perform
for_eachthe
argument
following actions:
# local_file.pet["/root/cats.txt"] will be created
+
onresource
main.tf "local_file"
line 2, in resource
"pet" {"local_file" "pet":
2: + directory_permission
for_each = var.filename = "0777"
+ file_permission = "0777"
The given
+ filename
"for_each" argument=value "/root/cats.txt"
is unsuitable: the "for_each"
argument
} must be a map, or set of strings, and you have provided a value
...
of type
<output
listtrimmed>
of string.
© Copyright KodeKloud Plan: 3 to
Check out ouradd, 0 to on
full course change, 0 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each

main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
type=set(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
]

>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform
Error: Invalid
will perform
for_eachthe
argument
following actions:
# local_file.pet["/root/cats.txt"] will be created
+
onresource
main.tf "local_file"
line 2, in resource
"pet" {"local_file" "pet":
2: + directory_permission
for_each = var.filename = "0777"
+ file_permission = "0777"
The given
+ filename
"for_each" argument=value "/root/cats.txt"
is unsuitable: the "for_each"
argument
} must be a map, or set of strings, and you have provided a value
...
of type
<output
listtrimmed>
of string.
© Copyright KodeKloud Plan: 3 to
Check out ouradd, 0 to on
full course change, 0 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each

main.tf variables.tf
variable "filename" {
resource "local_file" "pet" { type=list(string)
var.filename [count.index]
filename = each.value default
default == "/root/pets.txt"
[
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "/root/pets.txt",
"/root/dogs.txt",
} "/root/cats.txt"
output "pets" { ]
value = local_file.pet
}
}

>_
pet[0] pet[1] pet[2]
$ terraform plan
Terraform will perform
Error: Invalid for_eachthe following actions:
argument
# local_file.pet["/root/pets.txt"]
local_file.pet["/root/cats.txt"] will be destroyed created
+
onresource
- main.tf "local_file" "pet" {"local_file" "pet":
line 2, in resource
2: +
- directory_permission
for_each = var.filename = "0777" -> null
+
- file_permission = "0777" -> null
+
- filename
The given "for_each" argument=value "/root/pets.txt"
is unsuitable:
"/root/cats.txt" -> null
the "for_each"
}}
argument must be a map, or set of strings, and you have provided a value
... <output
of type listtrimmed>
of string.
© Copyright KodeKloud Plan: 03 to
Check out ouradd, 0 to on
full course change, 10 to
Terraform destroy.
for the Absolute Beginners: https://kode.wiki/3PoScZd
for_each

main.tf >_
$ terraform output
resource "local_file" "pet" { pets = {
var.filename [count.index]
filename = each.value "/root/cats.txt" = {
"directory_permission" = "0777"
for_each
count ==length(var.filename)
var.filename
3toset(var.filename) "file_permission" = "0777"
"filename" = "/root/cats.txt"
} "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
output "pets" {
value = local_file.pet "/root/dogs.txt" = {
} "directory_permission" = "0777"
"file_permission" = "0777"
"filename" = "/root/dogs.txt"
pet[0] pet[1] pet[2] "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
count for_each

>_ >_
$ terraform output $ terraform output
pets = [ pets = {
{ "/root/cats.txt" = {
"directory_permission" = "0777" "directory_permission" = "0777"
"file_permission" = "0777" "file_permission" = "0777"
"filename" = "/root/pets.txt" "filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709" "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
}, }
{
"directory_permission" = "0777"
"file_permission" = "0777" "/root/dogs.txt" = {
"filename" = "/root/dogs.txt" "directory_permission" = "0777"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709" "file_permission" = "0777"
}, "filename" = "/root/dogs.txt"
{ "id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
"directory_permission" = "0777" }
"file_permission" = "0777" }
"filename" = "/root/cats.txt"
"id" = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
},
]

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
HANDS-ON LABS

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Version Constraints
main.tf >_
resource "local_file" "pet" { $ terraform init
filename = "/root/pet.txt" Initializing the backend...
content = "We love pets!" Initializing provider plugins...
} - Finding latest version of hashicorp/local...
- Installing hashicorp/local v1.4.0...
- Installed hashicorp/local v1.4.0 (signed by HashiCorp)

The following providers do not have any version constraints


in configuration, so the latest version was installed.

To prevent automatic upgrades to new major versions that may


contain breaking
changes, we recommend adding version constraints in a
required_providers block
in your configuration, with the constraint strings suggested
below.

* hashicorp/local: version = "~> 1.4.0"

Terraform has been successfully initialized!

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "1.4.0"
}
}
}
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = { Initializing provider plugins...
source = "hashicorp/local" - Finding hashicorp/local versions matching "1.4.0"...
- Installing hashicorp/local v1.4.0...
version = "1.4.0" - Installed hashicorp/local v1.4.0 (signed by HashiCorp)
}
Terraform has been successfully initialized!
}
} You may now begin working with Terraform. Try running
"terraform plan" to see
any changes that are required for your infrastructure. All
resource "local_file" "pet" { Terraform commands
filename = "/root/pet.txt" should now work.
content = "We love pets!" If you ever set or change modules or backend configuration for
} Terraform,
rerun this command to reinitialize your working directory. If
you forget, other
commands will detect it and remind you to do so if necessary.

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = {
Initializing provider plugins...
source = "hashicorp/local" - Finding hashicorp/local versions matching "> 1.2.0, <
version
version == "1.4.0"
">
"<
"!=1.2.0,
1.4.0"
1.1.0"
2.0.0"< 2.0.0, != 1.4.0" 2.0.0, != 1.4.0"...
} - Installing hashicorp/local v1.3.0...
} - Installed hashicorp/local v1.3.0 (signed by
HashiCorp)
}
Terraform has been successfully initialized!
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
main.tf >_
terraform { $ terraform init
required_providers { Initializing the backend...
local = {
Initializing provider plugins...
source = "hashicorp/local"
- Finding hashicorp/local versions matching "~>
version
version === "1.4.0"
version ">
"!=1.2.0,
"<
"~> 2.0.0"< 2.0.0, != 1.4.0"
1.4.0"
1.1.0"
1.2"
1.2.0" 1.2.0"...
} - Installing hashicorp/local v1.2.2...
} - Installed hashicorp/local v1.2.2 (signed by
HashiCorp)
}
Terraform has been successfully initialized!
resource "local_file" "pet" {
filename = "/root/pet.txt"
content = "We love pets!"
}

© Copyright KodeKloud Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd
Check out our full course on Terraform for the Absolute Beginners: https://kode.wiki/3PoScZd

© Copyright KodeKloud
Certified Entry-Level Python
Programmer Certification (PCEP)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Basic
Data Types Operators
Concepts

Data
Flow Control Functions
Collections

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Introduction

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Easy and intuitive programming language
Free and Open Source
Can be widely used for a variety of tasks
🐍
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
bash

$ python3

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>> print ( "Hello future Python programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

$ python3
Python 3.8.2 (default, Oct 2 2020, 10:45:41)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information
>>> print ( "Hello future Python programmer!" )
Hello future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py

1 print ( "Hello future Python programmer!" )

bash

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py

1 print ( "Hello future Python programmer!" )

bash

$ python myfile.py

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
myfile.py

1 print ( "Hello future Python programmer!" )

bash

$ python myfile.py
Hello future Python programmer!
$

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Functions - Print()

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello future Python programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( " Hello future Python programmer! ")


Hello future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( " Hello future Python programmer! ")


Hello future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

Functions
>>> print ( " Hello future Python programmer! ")
A part of your code that’s used to
Hello future Python programmer!
cause an effect or evaluate a value.

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

Functions
>>> print ( " Hello future Python programmer! ")
A part of your code that’s used to
Hello future Python programmer!
cause an effect or evaluate a value.

Can come from:


• Python (built-in functions)
• Modules
• Your own code

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( " Hello future Python programmer! ")


Hello future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
Hello future Python programmer!

print ( " Hello future Python programmer! " )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( " Hello future Python programmer! ")


Hello future Python programmer!

>>> print("Python is a great language")


Python is a great language

>>> print("Strings don't get executed as code")


Strings don't get executed as code

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

Function Execution >>> print ( " Hello future Python programmer! ")
Hello future Python programmer!

Python:
1. Checks function name
2. Checks arguments passed
3. Jumps into the function
4. Executes the function
5. Returns to your code
6. Resumes execution

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello future Python programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello future Python programmer!" )


print("Python is a great language")
print("Strings don't get executed as code")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello future Python programmer!" )


print("Python is a great language")
print("Strings don't get executed as code")
Hello future Python programmer!
Python is a great language
Strings don't get executed as code

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello, \nfuture Python programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello,\nfuture Python programmer!" )


Hello,
future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello future Python programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello", "future", "Python", "programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello", "future", "Python", "programmer!" )


Hello future Python programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print("Hello!" )
print("Python is a great language")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print("Hello!" , end="" )


print("Python is a great language")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print("Hello!" , end="" )


print("Python is a great language")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print("Hello!" , end="" )


print("Python is a great language")
Hello!Python is a great language

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print("Hello!" , end="" )


print("Python is a great language")
Hello!Python is a great language

>>> print("Hello!" , end="!" )


print("Python is a great language")
Hello!!Python is a great language

>>> print("Hello!" , end="❤️" )


print("Python is a great language")
Hello!❤️Python is a great language

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello", "future", "Python", "programmer!" )

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hello", "future", "Python", "programmer!" , sep="-" )


Hello-future-Python-programmer!

>>> print "Hello", "future", "Python", "programmer!" , sep="❤️" )


Hello❤️future❤️Python❤️programmer!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> print ( "Hi", "Hello" , sep="! " , end="❤️\n" )


print ( "So", "enjoying python?" , sep= ", " , end="😄" )
Hi! Hello❤️
So, enjoying Python?😄

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
print()

• Built-in function: can be used without importing it.


• Allows us to print values to the console
• We can invoke it with parentheses.
• We can pass the value we want to print as arguments between the parentheses.
• The backslash \ tells python that the next character has a special meaning (eg. \n)
• Keyword arguments such as sep and end can be used to format the output.

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Literals

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
200 "Hello!" "Python" -89

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
200 "Hello!" "Python" -89

name c age print

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers
• Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types: 200 1298901


1. Integers
•Octal numbers
•Hexadecimal numbers
2. Floating point numbers -90 1_000_000
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers 0o123
• Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
0o123

Literal types:
1. Integers
•Octal numbers 2 1 0

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
0o123

Literal types:
1. Integers
•Octal numbers 82 81 80

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0o123

Literal types:
1. Integers
•Octal numbers 64 8 1

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
0o123

Literal types:
1. Integers
•Octal numbers
•Hexadecimal numbers 64 16 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers 0x123
•Octal numbers
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals
0x123

Literal types:
1. Integers
• Octal numbers 2 1 0

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123

Literal types:
1. Integers
• Octal numbers 16 2 161 160

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123

Literal types:
1. Integers
• Octal numbers 256 16 1

•Hexadecimal numbers 1 2 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123

Literal types:
1. Integers
• Octal numbers
•Hexadecimal numbers 256 32 3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals
0x123

Literal types:
1. Integers
•Octal numbers
•Hexadecimal numbers 291
256
32
3
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Literal types: 45.50 12.1


1. Integers
•Octal numbers
•Hexadecimal numbers
2. Floating point numbers -90.0 89.394
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers
•Octal numbers
0.0000000000000000000001
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers
•Octal numbers
1e-22
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Literal types:
"Hello!"
1. Integers
• Octal numbers
•Hexadecimal numbers 'Hello!'
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

'Hello! "Python" is cool'


Literal types:
1. Integers
•Octal numbers
•Hexadecimal numbers "Hello! 'Python' is cool"
2. Floating point numbers
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types:
1. Integers
• Octal numbers
"Hello! \"Python\" is cool"
•Hexadecimal numbers
2. Floating point numbers
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Literal types: True


1. Integers
•Octal numbers
•Hexadecimal numbers
2. Floating point numbers False
3. Strings
4. Booleans

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Literals

Literal types: True 1


1. Integers
• Octal numbers
•Hexadecimal numbers
2. Floating point numbers False 0
3. Strings
4. Booleans

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Literals

Numbers Strings Boolean

• Integers 123 • Double quotes "Hello!" • False False

•Octa 0o123 • Single quotes 'Hello!'


• True
l True

•Hexadecimal 0x123
• Use quotes 'Hi "hi"' • Numeric false 0
within strings

• Floating point 123.45 •Escape quotes 'Hi \'hi\'' • Numeric true 1

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Operators

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Arithmetic Operators

+ - * / // % **

Add Subtract Multiply Divide Floor Divide Modulo Exponential

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Arithmetic Operators

** 3
2
Exponential

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Arithmetic Operators

** 2True
** 3

Exponential

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(2 ** 3)
8
Arithmetic Operators >>> print(2. ** 3.)
8.0

>>> print(2 ** 3.)


**
8.0

>>> print(2. ** 3)
Exponential
8.0

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(2 * 3)
6
Arithmetic Operators >>> print(2. * 3.)
6.0

>>> print(2 * 3.)


*
6.0

>>> print(2. * 3)
Multiplication
6.0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(10 / 2)
5.0
Arithmetic Operators >>> print(10. / 2.)
5.0

>>> print(10 / 2.)


/
5.0

>>> print(10. / 2)
Division
5.0

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(10 // 2)
5
Arithmetic Operators >>> print(10. // 2.)
5.0

>>> print(10 // 2.)


//
5.0

>>> print(10. // 2)
Floor Division
5.0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(6. / 4)
1.5
Arithmetic Operators >>> print(6. // 4)
1.0
>>> print(6. / -4)
//
-1.5
>>> print(6. // -4)
Floor Division -2.0

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 % 2)

Arithmetic Operators

Modulo

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 % 2)

Arithmetic Operators

Modulo

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 % 2)

Arithmetic Operators

Modulo

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 % 2)
0
Arithmetic Operators

Modulo

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(5 % 2)

Arithmetic Operators

Modulo

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(5 % 2)

Arithmetic Operators

Modulo

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(5 % 2)

Arithmetic Operators

Modulo

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(5 % 2)
1
Arithmetic Operators

Modulo

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(5 % 2)
1
Arithmetic Operators

Modulo

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(6 + 4)
10
Arithmetic Operators >>> print(6. + 4)
10.0
>>> print(6. + 4.)
+
10.0

Addition

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(6 - 4)
2
Arithmetic Operators >>> print(6. - 4)
2.0
>>> print(6. - 4.)
-
2.0

Subtraction

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2

Binary Operator

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2

Binary Operator

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
2 - 2

Binary Operator

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
2 - 2 - 2

Binary Operator Unary Operator

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(-6 - 6)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(-6 - 6)
-12

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(-6 - 6)
-12

>>> print(10 - -6)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(-6 - 6)
-12

>>> print(10 - -6)


16

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> print(10 - 6 ** 7 / 9 * 23 + 1)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Highest Priority + - (unary)

**

* / // %

Lowest Priority + - (binary)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> print(10 - 6 ** 2 / 9 * 10 + 1)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 6 ** 2 / 9 * 10 + 1 )

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
print( 10 - 6 ** 2 / 9 * 10 + 1 )

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 36 / 9 * 10 + 1 )

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 4 * 10 + 1 )

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 40 + 1 )

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( 10 - 40 + 1 )

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
print( -30 + 1 )

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
print( -29 )

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> print(10 - 6 ** 7 / 9 * 10 + 1)
-29

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> print(2 * (2 + 3) )

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> print(2 * 5)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> print(2 * 5)
10

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Variables

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> print(2 * 5)
10

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> cost_of_apple = 5

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
10

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 5

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names

amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names

amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names

amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE del
elif
return

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names

amount_of_apples am*unt_o%_app|es
cost_of_apple c*st_o%_app|e
_total_cost 5apples_cost
COST_OF_APPLE del
elif
return

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Reserved Keywords

False elif lambda


None else nonlocal
True except not
and finally or
as for pass
assert from raise
break global return
class if try
continue import while
def in with
del is yield
© Copyright K odeK l oud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Valid Variable Names Invalid Variable Names

Import import
Del del
Elif elif
Return return

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 5

python3 python3

>>> cost_of_apple = cost_of_apple + 2

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 7

python3 python3

>>> cost_of_apple = cost_of_apple + 2

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 7

python3 python3

>>> cost_of_apple = cost_of_apple + 2


>>> print(amount_of_apples * cost_of_apple)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 7

python3 python3

>>> cost_of_apple == cost_of_apple + 2


>>> print(amount_of_apples * cost_of_apple)
18

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 5

python3

cost_of_apple = cost_of_apple + 2
>>>
>>> print(amount_of_apples * cost_of_apple)
14

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 5

python3
cost_of_apple += 2
>>>
>>> print(amount_of_apples * cost_of_apple)
14

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 5

python3 python3

>>> cost_of_apple += 2

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 7

python3 python3

>>> cost_of_apple += 2
>>> print(amount_of_apples * cost_of_apple)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
amount_of_apples cost_of_apple

2 7

python3 python3

>>> cost_of_apple += 2
>>> print(amount_of_apples * cost_of_apple)
18

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Without Shortcut Operator With Shortcut Operator

cost_of_apple = cost_of_apple + 2 cost_of_apple += 2


cost_of_apple = cost_of_apple - 2 cost_of_apple - = 2
cost_of_apple = cost_of_apple * 2 cost_of_apple * = 2
cost_of_apple = cost_of_apple ** 2 cost_of_apple ** = 2
cost_of_apple = cost_of_apple / 2 cost_of_apple / = 2
cost_of_apple = cost_of_apple // 2 cost_of_apple // = 2
cost_of_apple = cost_of_apple % 2 cost_of_apple %= 2

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Variables

• Variables allow you to store values


• A variable has a valid name (letters, digits, underscore, not a reserved keyword)
• Python is dynamically typed: variables can be redeclared
• We can use shortcut operators in order to cleanly redeclare a variable
• We can combine text and variables using the + operator in the print function
python3
python3

>>> print("One apple costs: " + cost_of_apple)


"One apple costs: 5"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Comments

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2 # Amount in basket

# The cost of an apple in USD


>>> cost_of_apple = 5

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2 # Amount in basket

# The cost of an apple in USD


# Should always be an integer
>>> cost_of_apple = 5

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2 # Amount in basket

# The cost of an apple in USD


# Should always be an integer
>>> cost_of_apple = 5

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> cost_of_apple = 5

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> # cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> amount_of_apples = 2
>>> # cost_of_apple = 5
>>> print(amount_of_apples * cost_of_apple)
NameError: name 'cost_of_apple' is not defined

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Input

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> print("Hello!")
Hello!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
input()

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> input("How are you feeling today? ")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> input("How are you feeling today? ")


How are you feeling today? Fantastic!

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3 python3

>>> input("How are you feeling today? ")


How are you feeling today? Fantastic!
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> favorite_color = input("What is your favorite color? ")

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> favorite_color = input("What is your favorite color? ")


What is your favorite color? blue

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> favorite_color = input("What is your favorite color? ")


What is your favorite color? blue
>>> print("Your favorite color is " + favorite_color)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> favorite_color = input("What is your favorite color? ")


What is your favorite color? blue
>>> print("Your favorite color is " + favorite_color)
Your favorite color is blue

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = input("How old are you? ")


How old are you? 22

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = input("How old are you? ")


How old are you? 22
>>> print(age - 10)

TypeError: unsupported operand type(s) for -: 'str' and 'int'

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = input("How old are you? ")


How old are you? 22

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Type Casting

• Integers int()

• Floating point float()

python3
python3

>>> age = input("How old are you? ")


How old are you? 22
>>> print(int(age) - 10)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Type Casting

• Integers int()

• Floating point float()

python3
python3

>>> age = input("How old are you? ")


How old are you? 22
>>> print(int(age) - 10)
12

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Type Casting

• Integers int()

• Floating point float()

python3
python3

>>> age = int(input("How old are you? "))


How old are you? 22
>>> print(age - 10)
12

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
input()

• Prompts the user to input some data from the console


• It accepts an optional parameter that can be used in order to write a
message before the user input
•Always returns a string
• A program that doesn’t use any input function, is called a deaf program

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


String Methods

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
+ *

python3
python3

>>> print(10 + 2)
12

>>> print(10 * 2)
22

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
+

python3
python3

>>> print(10 + 2)
12
>>> print("Hello" + " " + "there!")
"Hello there!"

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
*

python3
python3

>>> print(10 * 2)
22

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
*

python3
python3

>>> print(10 * 2)
22
>>> print("ha" * 10)
"hahahahahahahahahaha"

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
*

python3
python3

>>> print("ha" * 10)


"hahahahahahahahahaha"
>>> print("ha" * 2)
"haha"
>>> print("ha" * 0)
""
>>> print("ha" * -1)
""
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(int("22"))
22

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(int("22"))
22
>>> print(str(22))
"22"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)
>>> print("You have to pay: " + str(total_sum))

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> cost_of_apple = 2
>>> amount_of_apples = input("How many apples do you want? ")
How many apples do you want? 10
>>> total_sum = cost_of_apple * int(amount_of_apples)
>>> print("You have to pay: " + str(total_sum))
You have to pay: 20

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
String Operations

• You can use + in order to concatenate two strings


• You can use * in order to repeat a string a several amount of times.
• With the str function, you can type-cast a number into a string

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Comparison Operators

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Comparison Operators

== != > >= < <=

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(2 == 2)
True
Comparison Operators >>> print(2 == 4)
False
>>> print("Hello!" == "Hello!")
==
True
>>> print("Hello!" == “Goodbye!")
Equal False
>>> print(4 == (2 * 2))
True

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(2 != 2)
False
Comparison Operators >>> print(2 != 4)
True
>>> print("Hello!" != "Hello!")
!=
False
>>> print("Hello!" != “Goodbye!")
Not Equal True
>>> print(4 != (2 * 2))
False

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 > 2)


True
Comparison Operators >>> print(2 > 4)
False
>>> print(2 > 2)
>
False
>>> cost_of_apple = 2
Greater than
>>> cost_of_banana = 3
>>> print(cost_of_apple > cost_of_banana)
False

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 >= 2)


True
Comparison Operators >>> print(2 >= 4)
False
>>> print(2 >= 2)
>=
True

Greater than or equal to

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 < 2)


False
Comparison Operators >>> print(2 < 4)
True
>>> print(2 < 2)
<
False
>>> cost_of_apple = 2
Smaller than
>>> cost_of_banana = 3
>>> print(cost_of_apple < cost_of_banana)
True

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(4 <= 2)


False
Comparison Operators >>> print(2 <= 4)
True
>>> print(2 <= 2)
<=
True

Smaller than or equal to

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Comparison Operators

== != > >= < <=

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Conditional Statements

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if condition:

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
If True
condition :
print("The condition is true!")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition
: False :
print("The condition is true!")

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = int(input("How old are you? "))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = int(input("How old are you? "))


How old are you? 22

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = int(input("How old are you? "))


How old are you? 22
>>> if age >= 18:

print("You are an adult!")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = int(input("How old are you? "))


How old are you? 22
>>> if age >= 18:

print("You are an adult!")


You are an adult!

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")
else:
print("The condition is false!”)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if True
condition :
print("The condition is true!")
else:
print("The condition is false!")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if False
condition :
print("The condition is true!")
else:
print("The condition is false!")

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if condition :
print("The condition is true!")
elif second_condition :
print("Only the second condition is true!")
else:
print("Both conditions are false!”)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if False
condition :
print("The condition is true!")
elif True
second_condition :
print("Only the second condition is true!")
else:
print("Both conditions are false!”)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if True
condition :
print("The condition is true!")
elif True
second_condition :
print("Only the second condition is true!")
else:
print("Both conditions are false!”)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if age >= 18 :
if age == 18 :
print("You are exactly 18 years old!")
else:
print("You older than 18 years old!")

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
if age >= 18 :
if age == 18 :
print("You are exactly 18 years old!")
else:
print("You older than 18 years old!")

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
if age >= 18 :
if age == 18 :
print("You are exactly 18 years old!")
else:
print("You older than 18 years old!")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Loops - While

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
while condition:

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
while condition:

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4
Guess a number: 3

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
Guess a number: 0
Guess a number: 4
Guess a number: 3
>>>

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4
Guess a number: 3

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> secret_number = 3
>>> guess = int(input("Guess a number: "))
>>> while guess != secret_number:
guess = int(input("Guess a number: "))
else:
print("Congratulations, you got it!")
Guess a number: 0
Guess a number: 4
Guess a number: 3
Congratulations, you got it!
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Loops - For

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for … in …:

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for i in range(9):

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for i in range(9):

0 1 2 3 4 5 6 7 8 9

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for i in range(9):

0 1 2 3 4 5 6 7 8 9

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)
i is: 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)
i is: 0
i is: 1

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)
i is: 0
i is: 1
i is: 2

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)
i is: 0
i is: 1
i is: 2
i is: 3

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7
i is: 8
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4 5 6 7 8 9

python3
python3

>>> for i in range(9):


print("i is: ", i)

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
i is: 6
i is: 7
i is: 8
i is: 9
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
for i in range(2, 5):

2 3 4

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

python3
python3

>>> for i in range(5):


print("i is: ", i)
0
1
2
3
4

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

break
print("i is: ", i)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

break
print("i is: ", i)
0

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

break
print("i is: ", i)
0
1

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

break
print("i is: ", i)
0
1
>>>

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

python3
python3

>>> for i in range(5):


print("i is: ", i)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)
0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)
0
1

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)
0
1

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)
0
1
3

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
i

0 1 2 3 4

python3
python3

>>> for i in range(5):


if(i == 2):

continue
print("i is: ", i)
0
1
3
4

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
• if/else statements allow us to conditionally run code
• A while loop makes it possible to repetitively execute code
based on a certain condition

• We can execute code for each item in a sequence with a for … in loop

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Operators

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( Both ages are higher than 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( Both ages are higher than 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
True and True True

True and False False

False and True False

False and False False

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( One age is higher than 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( age1 >= 18 or age2 >= 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
True or True True

True or False True

False or True True

False or False False

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age1 = 24
>>> age2 = 16
>>> if( age1 >= 18 and age2 >= 18 ):
print("You are both adults")
elif( age1 >= 18 or age2 >= 18 ):
print("One of you is an adult")
else:
print("You are both children”)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
not True False

not False True

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> is_hungry = False


>>> if( not is_hungry ):
print("You are not hungry")

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> is_hungry = False


>>> if( not is_hungry ):
print("You are not hungry")
"You are not hungry"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Bitwise Operators

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Logical Operators

or and not

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Bitwise Operators

& | ~ ^

Conjunction Disjunction Negation Exclusive

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Bitwise Operators

& | ^

Two 1 At least one 1 Exactly 1

1 & 1 1 | 1 0 ^ 1

0 | 1 1 ^ 0

1 | 0
© Copyright K odeK l oud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> 15 & 22

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(bin(15))
0b1111

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(bin(15))
0b1111
>>> print(bin(22))
0b10110

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(bin(15))
0b1111
>>> print(bin(22))
0b10110

15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

&
22 0 0 0 1 0 1 1 0
Two 1

1 & 1

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

0 0 0 0 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

0 0 0 0 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

6 0 0 0 0 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 & 22)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 & 22)


6

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 | 22)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 | 0 1 1 1 1

At least one 1
22 0 0 0 1 0 1 1 0
1 | 1

0 | 1

1 | 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

0 0 0 1 1 1 1 1

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

31 0 0 0 1 1 1 1 1

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 | 22)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 | 22)


31

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(15 ^ 22)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1
^

22 0 0 0Exactly 1 1 0 1 1 0

0 ^ 1

1 ^ 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

0 0 0 1 1 1 0 1

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
15 0 0 0 0 1 1 1 1

22 0 0 0 1 0 1 1 0

25 0 0 0 1 1 0 0 1

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(~22)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
22 0 0 0 1 0 1 1 0

1 1 1 0 1 0 0 1

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
22 0 0 0 1 0 1 1 0

-23 1 1 1 0 1 0 0 1

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Without Shortcut Operator With Shortcut Operator

bit1 = bit1 & 22 bit1 &= 22


bit1 = bit1 | 22 bit1 |= 22
bit1 = bit1 ^ 22 bit1 ^= 22

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Bit Shifting

>> <<

Bit Shift Right Bit Shift Left

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)

22 0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)

22 0 0 0 1 0 1 1 0

0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)

22 0 0 0 1 0 1 1 0

0 0 0 0
1 0
1 0
1 1 1
0

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)

22 0 0 0 1 0 1 1 0

11 0 0 0 0
1 1
0 1
0 1 1
0

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 1)


11

22 0 0 0 1 0 1 1 0

11 0 0 0 0
1 0
1 0
1 1 0
1

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 2)

22 0 0 0 1 0 1 1 0

0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 >> 2)


5

22 0 0 0 1 0 1 1 0

5 0 0 0 0 0
1 1
0 0
1 1

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

0 0 0 1 0 1 1 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

0 0 0 1 0 1 1 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

0 0 0
1 0
1 0
1 1 1
0 0

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

44 0 0 0
1 1
0 1
0 1 1
0 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> print(22 << 1)

22 0 0 0 1 0 1 1 0

44 0 0 0
1 1
0 1
0 1 1
0 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
print(22 // 2) print(22 >> 1)

print(22 // 4) print(22 >> 2)

print(22 * 2) print(22 << 1)

print(22 * 4) print(22 << 2)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Operators

• Logical operators and not and or return boolean values based on the passed values
• Bitwise operators & | ^ and ~ allow us to manipulate single bits of data, and return
0 or 1 based on the value of the bits that are used

• Bit shifting can be done with the << and >> operators

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Lists

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> countries = ["USA", "Canada", "India"]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> countries = ["USA", "Canada", "India"]


>>>
US print(countries[0])

A
>>> print(countries[1])
Canada
>>> print(countries[2])
India

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries[0] = "UK"

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries[0] = "UK"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
len()

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> len(countries)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
len()

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> len(countries)
3

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> del countries[1]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1

"UK" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> del countries[1]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
-3 -2 -1

0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
-3 -2 -1

0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> print(countries[-1])

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
-3 -2 -1

0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> print(countries[-1])
"India"

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
-3 -2 -1

0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> print(countries[4])

IndexError: list index out of range

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Lists - Methods

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
list.append()

list.insert()

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Functions Methods

print() list.append()

len() list.insert()

input()

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
list.append()

list.insert()

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2

"UK" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries.append("Spain")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3

"UK" "Canada" "India" "Spain"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries.append("Spain")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3

"UK" "Canada" "India" "Spain"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries.append("Spain")
>>> countries.insert(2, "Italy")

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"UK" "Canada" "Italy" "India" "Spain"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries.append("Spain")
>>> countries.insert(2, "Italy")

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]
>>> countries[0] = countries[1]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "Canada" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]
>>> countries[0] = countries[1]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "Canada" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]
>>> countries[0] = countries[1]
>>> countries[1] = temp

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "Canada" "USA" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]
>>> countries[0] = countries[1]
>>> countries[1] = temp

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
temp 0 1 2

"USA" "Canada" "USA" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> temp = countries[0]
>>> countries[0] = countries[1]
>>> countries[1] = temp

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries[0], countries[1] = countries[1], countries[0]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

python3
countries[0], countries[1] = countries[1], countries[0]
>>> countries = ["USA", "Canada", "India"]
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2

"USA" "Canada" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries[0], countries[1] = countries[1], countries[0]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2

"Canada" "USA" "India"

python3
python3

>>> countries = ["USA", "Canada", "India"]


>>> countries[0], countries[1] = countries[1], countries[0]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
list.sort()

list.reverse()

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3

56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.sort()

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3

24 46 56 72

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.sort()
>>> print(ages)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3

24 46 56 72

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.sort()
>>> print(ages)
[24, 46, 56, 72]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3

56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.reverse()

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3

46 24 72 56

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.reverse()
>>> print(ages)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3

46 24 72 56

python3
python3

>>> ages = [56, 72, 24, 46]


>>> ages.reverse()
>>> print(ages)
[46, 24, 72, 56]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Iterating Lists

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3

56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

0 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

0 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

0 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

0 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

56 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

56 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

128 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

128 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

152 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

152 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age
>>> average = total / len(ages)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age
>>> average = total / len(ages)
>>> print(average)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
total 0 1 2 3

198 56 72 24 46

python3
python3

>>> ages = [56, 72, 24, 46]


>>> total = 0
>>> for age in ages:
total += age
>>> average = total / len(ages)
>>> print(average)
49.5
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Understanding Lists

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0

name

"Lydia"

python3
python3

>>> name = "Lydia"

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 40

name ages

56 72 24 46
"Lydia" <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 40

name ages

56 72 24 46
"Lydia" <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


92 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


92 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92
>>> print(ages2[0])

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


92 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92
>>> print(ages2[0])
92
© Copyright K odeK l oud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


56 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Slicing Lists

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
list[start:end]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]
>>> print(firstTwo)
["A", "B" ]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]
>>> print(firstTwo)
["A", "B" ]
>>> print(letters[1:])

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]
>>> print(firstTwo)
["A", "B" ]
>>> print(letters[1:])
["B", "C", "D", "E"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]
>>> print(firstTwo)
["A", "B" ]
>>> print(letters[1:])
["B", "C", "D", "E"]
>>> print(letters[:3])

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> firstTwo = letters[0:2]
>>> print(firstTwo)
["A", "B" ]
>>> print(letters[1:])
["B", "C", "D", "E"]
>>> print(letters[:3])
["A", "B", "C"]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print(letters[1:-1])
["B", "C", "D"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print(letters[:])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print(letters[:])
["A", "B", "C", "D", "E"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


92 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92
>>> print(ages2[0])
92
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print(letters[:])
["A", "B", "C", "D", "E"]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[1:3]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[1:3]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[1:3]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2

"A" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[1:3]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[:]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[:]
>>> print(letters)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> del letters[:]
>>> print(letters)
[]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Finding in Lists

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
element in list

element not in list

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print("B" in letters)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print("B" in letters)
True

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print("B" in letters)
True
>>> print("Z" in letters)
False

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print("B" not in letters)
False
>>> print("Z" not in letters)
True

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 2 3 4

"A" "B" "C" "D" "E"

python3
python3

>>> letters = ["A", "B", "C", "D", "E"]


>>> print("B" not in letters)
False
>>> print("Z" not in letters)
True

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Nested Lists - 2D
(Matrix)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
classroom = [ ["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>>
student = classroom[2]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>>
student = classroom[2]

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]
>>> print(student)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
["Sam", =
classroom "Max",
[ "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
>>> student = classroom[2][1]
>>> print(student)
"Sara"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Nested Lists - 3D
(Cube)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] [1] Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> school = [
[
["Sara", "Kim", "Anne", "Eva"],
["Johan", "Collin", "Sam", "Alex"],
["Luke", "Sara", "Haley", "Jennifer"],
["Katy", "Mara", "Max", "Roy"],
],
[
["Anne", "Leo", "Sasha", "Tim"],
["Claire", "Guy", "Eva", "Zoe"],
["Lisa", "Max", "Evan", "Chloe"],
["Brent", "Sam", “Sarah", "Anne"],
],
[
["Maria", "Julian", "Chris", "Tom"],
["Zoe", "Anna", "Kim", "Leo"],
["Vera", "Pim", "Leo", "Guy"],
["Anne", "Sofie", "Max", "Joe"],
],
[
["Sam", "Max", "Joe", "Anne"],
["Sofie", "Lisa", "Tim", "Sasha"],
["Claire", "Sara", "Leo", "Kim"],
["Zoe", "Guy", "Anna", "Eva"],
]
]
© Copyright KodeKloud
>>> student = school[1] [2] [1] Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> student = school[1] [2] [1]


>>> print(student)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> student = school[1] [2] [1]


>>> print(student)
"Max"

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Functions

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Functions Methods

print() list.append()

len() list.insert()

input()

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))

python3

>>> def input_number():


return int(input("Enter a number: "))

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = int(input("Enter a number: "))


>>> input3 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))
def input_number():
return int(input("Enterpython3
a number: "))
>>>

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))

python3

>>> input1 = int(input("Enter a number: "))


>>> input2 = int(input("Enter a number: "))
>>> input3 = int(input("Enter a number: "))
>>> input4 = int(input("Enter a number: "))
>>> input5 = int(input("Enter a number: "))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104
>>> input2

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104
>>> input2
Enter a number: 34

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104
>>> input2
Enter a number: 34
>>> print(input2)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104
>>> input2
Enter a number: 34
>>> print(input2)
34
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


return int(input("Enter a number: "))
>>> input1 = input_number()
>>> input2 = input_number()
>>> input3 = input_number()
>>> input4 = input_number()
>>> input5 = input_number()
>>> input1
Enter a number: 104
>>> print(input1)
104
>>> input2
Enter a number: 34
>>> print(input2)
34
© Copyright K odeK l oud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = input_number()

def input_number():
return int(input("Enter a number: "))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> input1 = input_number()

def input_number():
return int(input("Enter a number: "))

NameError: name 'input_number' is not defined

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Function - Arguments

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number( ):
return int(input("Enter a number: "))

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number( num ):
return int(input("Enter a number: ")) * num

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
>>>
def input_number( num ):
return int(input("Enter a number: ")) * num

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num
>>> input1 = input_number(10)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num
>>> input1 = input_number(10)
>>> input1

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num
>>> input1 = input_number(10)
>>> input1
Enter a number: 12

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num
>>> input1 = input_number(10)
>>> input1
Enter a number: 12
>>> print(input1)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num
>>> input1 = input_number(10)
>>> input1
Enter a number: 12
>>> print(input1)
120

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number(num1, num2):


return int(input("Enter a number: ")) * num1 - num2

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number(num1, num2):


return int(input("Enter a number: ")) * num1 - num2
>>> input1 = input_number(10, 20)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2

input1 = input_number( 10, 20)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2

input1 = input_number( 10, 20)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2

input1 = input_number( num2 = 10, num1 = 20)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2

input1 = input_number( num2 = 10, num1 = 20)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>>
def input_number(num1, num2):
return int(input("Enter
>>> a number: ")) * num1 - num2

input1 = input_number(10, num1 = 20)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number(num1, num2):


return int(input("Enter a number: ")) * num1 - num2
>>> input1 = input_number(10, num1 = 20)

TypeError: input_number() got multiple values


for argument 'num1'

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num ):


return int(input("Enter a number: ")) * num

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number()

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number()
Enter a number: 12

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number()
Enter a number: 12
120

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number()
Enter a number: 12
120

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number(5)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number(5)
Enter a number: 12

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number(5)
Enter a number: 12
60

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num
>>> input_number(5)
Enter a number: 12
60

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Function - Return

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number( num = 10 ):


return int(input("Enter a number: ")) * num

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
print("The sum is: ", str(sum))

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
print("The sum is: ", str(sum))
>>> print_sum(10, 20)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
print("The sum is: ", str(sum))
>>> print_sum(10, 20)
The sum is: 30

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
print("The sum is: ", str(sum))
>>> print_sum(10, 20)
The sum is: 30

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
return
print("The sum is: ", str(sum))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2
return
print("The sum is: ", str(sum))

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)
The sum is: 6

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def print_sum( num1, num2 ):


sum = num1 + num2

if(sum == 0):
return

print("The sum is: ", str(sum))

>>> print_sum(4, 2)
The sum is: 6
>>> print_sum(-1, 1)
>>>

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def is_even( num ):


if(num % 2 == 0):
return True

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def is_even( num ):


if(num % 2 == 0):
return True
>>> print(is_even(6))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def is_even( num ):


if(num % 2 == 0):
return True
>>> print(is_even(6))
True

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def is_even( num ):


if(num % 2 == 0):
return True
>>> print(is_even(6))
True
>>> print(is_even(7))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def is_even( num ):


if(num % 2 == 0):
return True
>>> print(is_even(6))
True
>>> print(is_even(7))
None

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Function - List as Argument

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))


[2, 4, 6]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))


[2, 4, 6]
>>> print(multiply_values([-4, -8, -10]))

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))


[2, 4, 6]
>>> print(multiply_values([-4, -8, -10]))
[-8, -16, -20]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))


[2, 4, 6]
>>> print(multiply_values([-4, -8, -10]))
[-8, -16, -20]
>>> print(multiply_values(1))

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def multiply_values(list):


multiplied_values = []

for item in list:


multiplied_values.append(item * 2)

return multiplied_values

>>> print(multiply_values([1, 2, 3]))


[2, 4, 6]
>>> print(multiply_values([-4, -8, -10]))
[-8, -16, -20]
>>> print(multiply_values(1))

TypeError: 'int' object is not iterable

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Scopes

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


result = int(input("Enter a number: ")) * 100
return result

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


result = int(input("Enter a number: ")) * 100
return result

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


result = int(input("Enter a number: ")) * 100
return result
>>> print(result)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> def input_number():


result = int(input("Enter a number: ")) * 100
return result
>>> print(result)
NameError: name 'result' is not defined

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
nu
result = int(input("Enter a number: ")) *
return result m

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
num = 50 nu
result = int(input("Enter a number: ")) *
return result m

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
num = 50 nu
result = int(input("Enter a number: ")) *
return result m

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
nu
result = int(input("Enter a number: ")) *
return result m

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
own_num = 50 own_nu
result = int(input("Enter a number: ")) *
return result m
>>> print(own_num)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
own_num = 50 own_nu
result = int(input("Enter a number: ")) *
return result m
>>> print(own_num)
NameError: name 'own_num' is not defined

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
own_nu
global
m
own_num = 50 own_nu
result = int(input("Enter a number: ")) *
return result m

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
global own_num
own_num = 50
result = int(input("Enter a number: ")) * own_num
return result
>>> print(own_num)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3

>>> num = 100


>>> def input_number():
global own_num
own_num = 50
result = int(input("Enter a number: ")) * own_num
return result
>>> print(own_num)
50

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Function - Arguments Explained

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 2 40

name ages ages2


92 72 24 46
"Lydia" <40> <40>

python3
python3

>>> name = "Lydia"


>>> ages = [56, 72, 24, 46]
>>> ages2 = ages
>>> ages[0] = 92
>>> print(ages2[0])
92
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)
22

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0

age

22

python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1

age num

22 22

python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1

age num

22 44

python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1

age num

22 44

python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1

age num

22 44

python3
python3

>>> age = 22
nu
>>> def multiply( ):
nu
*= 2 m
m
print("In multiply: ", str(num))
>>> multiply(age)
In multiply: 44
>>> print(age)
22

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40

nums
1 2 3
<40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40

nums
1 2 3
<40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40

nums
1 2 3
<40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 40

nums
1 2 3
<40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9
>>> change_first_item(nums)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
0 1 40

nums list
1 2 3
<40> <40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9
>>> change_first_item(nums)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 40

nums list
9 2 3
<40> <40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9
>>> change_first_item(nums)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 40

nums list
9 2 3
<40> <40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9
>>> change_first_item(nums)
>>> print(nums)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
0 1 40

nums list
9 2 3
<40> <40>

python3
python3

>>> nums = [1, 2, 3]


>>> def change_first_item(list):
list[0] = 9
>>> change_first_item(nums)
>>> print(nums)
[9, 2, 3]

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright KodeKloud
Tuples

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
[1, 2, 3]

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
[1, 2, 3]

del myList[1]

myList.append(4)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> print(tuple1)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> print(tuple1)
(1, 2, 3)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> print(tuple1)
(1, 2, 3)
>>> tuple2 = 1, 2, 3

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> print(tuple1)
(1, 2, 3)
>>> tuple2 = 1, 2, 3
>>> print(tuple2)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> print(tuple1)
(1, 2, 3)
>>> tuple2 = 1, 2, 3
>>> print(tuple2)
(1, 2, 3)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> for item in tuple1:
print(item)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> for item in tuple1:
print(item)
1
2
3

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> for item in tuple1:
print(item)
1
2
3
>>> print(tuple1[0:1])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> for item in tuple1:
print(item)
1
2
3
>>> print(tuple1[0:1])
(0, 1)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> tuple1.append(4)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> tuple1.append(4)
AttributeError: 'tuple' object has no attribute 'append'

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> tuple1.append(4)
AttributeError: 'tuple' object has no attribute 'append'

>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> tuple1.append(4)
AttributeError: 'tuple' object has no attribute 'append'

>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment
>>> del tuple1[1]
TypeError: 'tuple' object doesn't support item deletion

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1, 2, 3)


>>> tuple1.append(4)
AttributeError: 'tuple' object has no attribute 'append'

>>> tuple1[4] = 9
TypeError: 'tuple' object does not support item assignment
>>> del tuple1[1]
TypeError: 'tuple' object doesn't support item deletion

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> age = 22
>>> tuple1 = (1, "Lydia", age, (1, 2))

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>> tuple1 = (1,)


>>> tuple2 = 1,

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU

© Copyright K odeK l oud


Dictionaries

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Name Username

lydia lydiahallie

sarah sarah123

max
max
_

joe joejoe

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
"lydia": "lydiahallie",
usernames ={
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["sarah"])
"sarah123"

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["anotherone"])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames["anotherone"])
KeyError: 'anotherone'

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Methods

dictionary.keys()

dictionary.values()

dictionary.items()

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.keys())

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

>>> print(usernames.keys())
dict_keys(['lydia', 'sarah', 'max', ‘joe'])

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.keys())

dict_keys(['lydia', 'sarah', 'max', ‘joe'])

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3
python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

>>> for key in usernames.keys():


print(key + " - " + usernames[key])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3
python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

>>> for key in usernames.keys():


print(key + " - " + usernames[key])
lydia - lydiahallie
sarah - sarah123
max - max_
joe - joejoe

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.values())

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.values())

dict_values(['lydiahallie', 'sarah123', ‘max_', 'joejoe'])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.items())

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> print(usernames.items())
dict_items([
('lydia', 'lydiahallie'),
('sarah', 'sarah123'),
('max', 'max_')
('joe', 'joejoe')
])

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
Methods

dictionary.keys()

dictionary.values()

dictionary.items()

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

>>> usernames["max"] = "max123"

© Copyright K odeK l oud


Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames["max"] = "max123"
>>> print(usernames["max"])

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames["max"] = "max123"
>>> print(usernames["max"])
"max123"

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })
>>> print(usernames)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.update({ "chloe": "chloe123" })
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
"chloe": "chloe123"
}
© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]
>>> print(usernames)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> del usernames["max"]
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"joe": "joejoe"
}

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()
>>> print(usernames)

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.clear()
>>> print(usernames)
{}

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>> usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.popitem()
>>> print(usernames)

© Copyright K odeK l oud


Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames.popitem()
>>> print(usernames)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_"
}

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()

© Copyright KodeKloud
Check out our full course on Python E ntry-Level Programmer Certification (PCE P): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()
>>> print(usernames_copy)

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
python3python3

>>>
usernames = {
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe",
}
>>> usernames_copy = usernames.copy()
>>> print(usernames_copy)
{
"lydia": "lydiahallie",
"sarah": "sarah123",
"max": "max_",
"joe": "joejoe"
}

© Copyright KodeKloud
Check out our full course on Python Entry-Level Programmer Certification (PCEP): https://kode.wiki/3NnDTlU
Learn more about DevOps and Cloud courses with KodeKloud: https://kode.wiki/3N3A4kt

© Copyright KodeKloud

You might also like