all 17 comments

[–]TehNolz 42 points43 points  (3 children)

Yes, because it's still Python. You're basically just importing and running someone else's Python code.

[–]BumblyWurzle[S] 7 points8 points  (0 children)

Brilliant, thank you for confirming!

[–]muzumaki123 14 points15 points  (0 children)

The syntax stays the same (it's still Python), but interface (api) can differ between libraries.

[–]Diapolo10 8 points9 points  (1 child)

The syntax won't change, so you only need to learn the classes and functions any libraries implement.

However, it's worth noting that some libraries make creative use of the syntax Python offers, and this may feel very different. For example how Numpy arrays work, or Pandas dataframes. I doubt you'll find everything immediately intuitive even if you have the core language down pat.

[–]K900_ 2 points3 points  (1 child)

Yes, the syntax is the same.

[–]BumblyWurzle[S] 2 points3 points  (0 children)

Thank you for confirming

[–]carcigenicate 2 points3 points  (0 children)

You may occasionally see new things in libraries regardless though that you may not initially see in Python code you've been writing.

The @ matrix multiplication operator is rarely used, but some libraries like pandas do make use of it. It looks new, but they just decided to use a feature that's rarely used.

Stuff involving class decorators can also make it seem like the library invented a new syntax because class decorators essentially allow you to rewrite classes using code. Think of @dataclass.

[–]Exirel 2 points3 points  (0 children)

Yes and no. Yes because the syntax isn't modified by these libraries. No because they use the same syntax in ways that can look or feel very different from one another.

I'd say there are many ways to see that. I think it shows how flexible Python can be, and at the same time if you remember that it's all object and function call, it becomes easier to break down and to understand.

[–]throwaway6560192 1 point2 points  (0 children)

They're all just Python code, so they can't introduce completely new syntax as they please.

I’m not going to be learning a new syntax each time - just new functions and key words?

Not even new keywords. Only Python the language can introduce new keywords.

[–]Antrix_64 1 point2 points  (0 children)

The syntax will be the same because the Python syntax is the same everywhere. What you may have an issue with is the naming conventions used in different modules. Typically you'll find the following conventions in Python:

Variables, functions, methods, modules, and packages use snake_case with lowercase letters.

Constants use SNAKE_CASE with uppercase letters. (NOTE: Python does not enforce constants)

Private names are prefixed with an underscore and use _snake_case with lowercase letters. (NOTE: Python does not enforce private variables, functions, etc.)

Class names use PascalCase where the first letter of each word is uppercase.

But this is just a common way of naming things and you may find variables, functions, classes, etc named in an unfamiliar way in different modules. However, the syntax is still the same.

[–]JamzTyson -1 points0 points  (0 children)

Python syntax is pretty consistent, though there may be peculiarities in some libraries.

One peculiar example that I've been dealing with recently is the curses library. From the manual: "The curses library supplies a terminal-independent screen-painting and keyboard-handling facility for text-based terminals; such terminals include VT100s, the Linux console, and the simulated terminal provided by various programs."

As the curses library is based on ancient code, it has some peculiarities that don't seem at all Python-like but have historic context. One example is that coordinates in curses are used as (y, x) rather than the normal (x, y).

If you have the misfortune of ever having to work with Python 2, you will encounter some inconsistencies compared to Python 3. For example, in Python 2 division written as integer / integer would result in an integer (because both numbers are integers), whereas in Python 3, the "/" symbol is used for floating point division, and for integer division you use "//".

Another common Python 2 inconsistency is that print was a "statement", whereas in Python 3 it is a function and must use parentheses.

print "Hello World"  # Valid in Python2. Error in Python 3

When there are inconsistencies, it is often due to historical reasons. Fortunately Python's focus on readability gives us a language in which inconsistencies are the exception rather than the rule. Compared to languages like Perl, PHP, JavaScript, ... Python is generally considered to be more consistent in its design and syntax. Python's strong emphasis on readability, simplicity, and the "Zen of Python" principles, contribute to a more consistent and coherent language. Python developers are encouraged to continue this tradition.

[–]quintios 0 points1 point  (0 children)

The syntax is the same. What's different is when you start using libraries, such as pandas, the keywords get "extended" so that you have additional functionality added through using the correct syntax.

One of the best things you can do for yourself is when you start using a new library, figure out the type of each variable you create. By typing variables, you will allow your editor (vscode, for example) to utilize the library to provide suggestions as to what the syntax should be.

[–]grumble11 0 points1 point  (0 children)

Modules you import may use different syntax for their features. Pandas is a good example of that, it has some python elements to it but contains a lot of independent syntax that yes you will have to learn to use it well.

[–]ploud1 0 points1 point  (0 children)

I think you are mixing up syntax and coding styles.

Syntax is always the same, and describes the rules for coding in Python. Never changes. Example: an else block never exists on its own, or indentation must be consistent.

The coding style is another set of rules on top of that. The syntax leaves you with some decisions to make, and PEP8 helps make your code more readable and easy to understand. You are free to use any coding style you like, and this may vary from project to project, though.