[SOLVED] Declare variables types for python function triggers invalid syntax error


I am having trouble why I am getting an invalid syntax error when I declare what my variable is inside my function. The function works when I step through it in python, but not when I try to run the program from the command line.

command line code:

python filename.py

python code:

import pandas as pd
def my_func(df:pd.DataFrame,name:str):
    print("Hello world")
def main():
if __name__ == "__main__":


Your code is perfectly valid. Check your Python version – you’re probably using a version that doesn’t support type hints, such as Python 2.

(Perhaps python resolves to python2?)

Answered By – richardec

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *