C++ for Python Developers
Transfer Python experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.
Python and C++ side by side
The same program in Python and in C++, from the lessons of this course.
Strings and Output
Python str is immutable Unicode text; C++ std::string is a mutable byte sequence with explicit ownership. C++ std::string owns a mutable byte sequence; stream insertion formats values. Length counts bytes, not Unicode characters.
Python1print(len("oak"))C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string name="oak";std::cout<<name.size()<<"\n";15}Text Equality
Python == asks value equality while is asks identity. C++ operator behavior depends on the declared operand types. C++ std::string equality compares contents. Raw pointer equality compares addresses; user classes need a deliberate equality operation.
Python1a = ["red"]2b = ["red"]3print(a == b)4print(a is b)C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string a="red",b="red";std::cout<<std::boolalpha<<(a==b)<<"\n";15}Fixed-size Arrays
Python lists are resizable reference containers; C++ std::array has a compile-time length and value-copy behavior. C++ std::array<T,N> is a fixed-size value type. Its size is part of its type, and normal copy duplicates its elements.
Python1items = [4, 8]2items.append(12)3print(items[-1])4print(items[:2])C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::array<int,3> a{4,5,6};std::cout<<a.size()<<" "<<a.at(1)<<"\n";15}Value Copies
Python assignment shares an object and shallow copy retains nested aliases. C++ vector copy copies its elements according to their types. C++ vector and string copies own independent storage. Copying a raw pointer still shares the pointed-to object and does…
Python1original = [[1]]2copy = original.copy()3copy[0].append(2)4print(original)5print(sorted({3, 1, 3}))C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::vector<int> a{4};auto b=a;b.push_back(9);std::cout<<a.size()<<" "<<b.size()<<"\n";15}Functions and Returns
Python functions are runtime objects with dynamic calls. C++ function signatures are statically checked. C++ function declarations establish parameter and return types. A return value is not automatically printed.
Python1def twice(value):2 return value * 23print(twice(4))C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12int triple(int n){return 3*n;}13int main(){14std::cout<<triple(4)<<"\n";15}Streams and Exact Parsing
Python int conversion raises ValueError for invalid numeric text. C++ streams represent extraction failure in stream state. C++ stream extraction reports success through stream state. Validate conversion and reject unexpected trailing tokens when the contract…
Python1word, number = "oak 7".split()2print(f"{word}/{int(number)}")C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::istringstream in("oak 7");std::string word;int n;if(in>>word>>n)std::cout<<word<<"/"<<n<<"\n";15}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsC++ Files and Values
6 lessonsConditions and Iteration
5 lessonsStandard Containers
5 lessonsCopies and Algorithms
5 lessonsFunctions and Templates
5 lessonsParsing and Lifetime
5 lessonsObjects and Invariants
6 lessonsComposition and Ownership
5 lessonsProject: Library Desk
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is C++ for Python Developers for?
For people who already write Python and want to learn C++. Each lesson starts from Python you know and shows how C++ does the same thing, so you skip the beginner basics.
Do I need to know C++ already?
No. The course starts with your first C++ program. You need Python basics: variables, conditions, loops, functions and collections.
How many lessons does C++ for Python Developers have?
C++ for Python Developers contains 48 interactive lessons you can complete at your own pace.
What does C++ for Python Developers cover?
The course is organized into chapters covering: C++ Files and Values, Conditions and Iteration, Standard Containers, Copies and Algorithms, and more.
Is C++ for Python Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.