Learning Python & C++: Is It Easy?

  • Thread starter Winzer
  • Start date
  • Tags
    Python
In summary: IMO.Thanks for the book pointer,In summary, Python is easy to learn for someone coming from a higher level language, and it is a good tool for prototyping. C++ (or Fortran) is a better language for doing computationally intense tasks, but Python can be used to interface with these programs. Swig is a great tool for wrapping C/C++ code so that it can be used with Python, but it is not the best option for those starting out. Ctypes is a better option for those wanting to use C++ code with Python.
  • #1
Winzer
598
0
I am learning Python right now and it is pretty cool. Just out of curiosity, would it be a easy transition to learn C++ after I master Python?
 
Technology news on Phys.org
  • #2
Why would you want to!
Often people coming from a higher level language write better C++ code (using boost and STL) rather than people coming from C/Fortran who write at too low a level.
 
  • #3
Boost and STL, never heard of them. I am new to programming:)

Well, I have noticed some really good computational software that requires C++, like open foam for CFD.
I would like to eventually get into these types of programs.
 
  • #4
So boost allows me to interface python with c++ programs, is that correct?
So I would be able to use python for open foam?
 
  • #5
If you do a lot of intense computations such as CFD, it does not hurt to start programming in C++ which gives you a lot more return for your CPU seconds.
Python and other high level languages make excellent prototyping tools.
 
  • #6
If you have an existing CFD (or whatever) library it might be worth looking for a Python wrapper, or making some wrappers using boost::python.
Let C++ (or Fortran) do the heavy lifting an write your own program on top of this in Python - you get a lot better value for your programming hours and a reduction in all-night bug hunts.
 
  • #7
For what little it's worth, I've often found Boost::Python to be perhaps the most severely lacking component in the Boost libraries. (The reasons are technical and I won't discuss them here.)

On the other hand, Swig is a great way of wrapping C/C++ code so that it can be used with Python (among many other languages). It's discussed in several places but a really useful introduction to it, as well as to the use of Python more generally in a scientific context, is Langtangen's https://www.amazon.com/dp/3540739157/?tag=pfamazon01-20. (Langtangen's book is wonderful for many reasons but it also does a really good job of illustrating how Python can be used to interface with Fortran and C/C++ code, something that's essential knowledge if you're going to be working with scientific libraries.)
 
Last edited by a moderator:
  • #8
Thanks for the book pointer,
I've noticed a couple of projects switching back to SWIG. When I last used it I remember it generated a very 'c' like interface, I've only used boost:python for a few trial projects.
 
  • #9
mgb_phys said:
Thanks for the book pointer,

I really can't recommend it highly enough. It takes a bit of effort, but there's an enormous amount of useful information in there, particularly regarding Numpy and wrapping Fortran or C/C++ code in Python. It's a gem of a book.
 
  • #10
shoehorn said:
For what little it's worth, I've often found Boost::Python to be perhaps the most severely lacking component in the Boost libraries. (The reasons are technical and I won't discuss them here.)

On the other hand, Swig is a great way of wrapping C/C++ code so that it can be used with Python (among many other languages). It's discussed in several places but a really useful introduction to it, as well as to the use of Python more generally in a scientific context, is Langtangen's https://www.amazon.com/dp/3540739157/?tag=pfamazon01-20. (Langtangen's book is wonderful for many reasons but it also does a really good job of illustrating how Python can be used to interface with Fortran and C/C++ code, something that's essential knowledge if you're going to be working with scientific libraries.)
I have Langtangen and agree it's excellent. I'd disagree w/ the recommendation of Swig now, especially for those starting out. Ctypes IMO has eclipsed it as the best bet: far easier to use, learn, and debug, comes builtin w/ Python, and for some things out performs Swig substantially. Downside is Ctypes won't handle C++
 
Last edited by a moderator:

1. Is learning Python & C++ difficult for beginners?

Learning any programming language can be challenging, but Python and C++ are often recommended as good languages for beginners due to their user-friendly syntax and extensive online resources available. With dedication and practice, anyone can learn Python & C++.

2. Can I learn both Python & C++ at the same time?

While it is possible to learn both languages simultaneously, it is generally recommended to focus on one at a time. Python and C++ have different syntax and structures, so learning them separately can help prevent confusion and allow for a deeper understanding of each language.

3. How long does it take to learn Python & C++?

The time it takes to learn Python & C++ varies depending on individual learning speed and the amount of time dedicated to studying. With consistent practice and dedication, one can become proficient in both languages in a few months.

4. What are the main differences between Python & C++?

Python is a high-level, interpreted language that is known for its simplicity and readability. It is often used for web development, data analysis, and artificial intelligence. C++ is a low-level, compiled language that is known for its speed and efficiency. It is often used for system and application development.

5. Can I use Python & C++ for the same purposes?

While both languages have their own strengths and purposes, they can be used for similar tasks such as web development, data analysis, and scripting. However, C++ is better suited for low-level tasks and performance-critical applications, while Python is better for high-level tasks and prototyping.

Similar threads

  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
Replies
6
Views
643
  • Programming and Computer Science
Replies
1
Views
726
  • Programming and Computer Science
Replies
3
Views
586
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
881
  • Programming and Computer Science
Replies
5
Views
845
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top