# C++ Has Become More Pythonic

DevFeed: [C++ Has Become More Pythonic](<https://devfeed.tech/articles/c-has-become-more-pythonic-21000.md>)

Original publisher: [Read original article](<https://preshing.com/20141202/cpp-has-become-more-pythonic>)

Author: Jeff Preshing

Published: 2014-12-02T13:20:00Z

Content type: comparison

Language: en

Sources: [Jeff Preshing](<https://devfeed.tech/sources/jeff-preshing.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Python](<https://devfeed.tech/topics/python.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [features](<https://devfeed.tech/tags/features.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [loops](<https://devfeed.tech/tags/loops.md>), [map](<https://devfeed.tech/tags/map.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

## AI overview

The article argues that modern C++, particularly C++11 and C++14, has adopted a programming style with notable similarities to Python. It compares features including binary and raw string literals, range-based for loops, type deduction with auto, tuples, and initialization syntax, while considering whether Python directly influenced these developments.

## Source excerpt

C++ has changed a lot in recent years. The last two revisions, C++11 and C++14, introduce so many new features that, in the words of Bjarne Stroustrup, "It feels like a new language." It's true. Modern C++ lends itself to a whole new style of programming - and I couldn't help noticing it has more of a Python flavor. Ranged-based for loops, type deduction, vector and map initializers, lambda expressions. The more you explore modern C++, the more you find Python's fingerprints all over it. Was Python a direct influence on modern C++? Or did Python simply adopt a few useful constructs before C++ got around to it? You be the judge. Literals Python introduced binary literals in 2008. Now C++14 has them. [Update: Thiago Macieira points out in the comments that GCC actually supported them back in 2007.] static const int primes = 0b10100000100010100010100010101100; Python also introduced raw string literals back in 1998. They're convenient when hardcoding a regular expression or a Windows path. C++11 added the same idea with a slightly different syntax: const char* path = R"(c:\this\string\has\backslashes)"; Range-Based For Loops In Python, a for loop always iterates over a Python object: for x in myList: print(x) Meanwhile, for nearly three decades, C++ supported only C-style for loops. Finally, in C++11, range-based for loops were added: for (int x : myList) std::cout << x; You can iterate over a std::vector or any class which implements the begin and end member functions - not unlike Python's iterator protocol. With range-based for loops, I often find myself wishing C++ had Python's xrange function built-in. Auto Python has always been a dynamically typed language. You don't need to declare variable types anywhere, since types are a property of the objects themselves. x = "Hello world!" print(x) C++, on the other hand, is not dynamically typed. It's statically typed. But since C++11 repurposed the auto keyword for type deduction, you can write code that looks a lot like