• Register
0 votes
26 views

I am a newbee. I was doing my coding practice. I was trying to check if a variable exist in a file or not. I wrote some code to do this :

def Check():
  if Check.my_variable is None:
     Check.my_variable = >>>
  Check.my_variable = None

 but it gives me error :

 File "main.py", line 3
    Check.my_variable = >>>
                        ^
SyntaxError: invalid syntax

What is the error in my code and why am I getting this type of error. 

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

You are getting this error becuse of your conditon for your program should be True, False Or None or you have an empty srting list.

You should write your code like:

def Check():
  if Check.my_variable is None:
     Check.my_variable = ...
  Check.my_variable = None

Please use this code and let me know if this is working properly for you or not. I am sure that you can get the exact result using this code. 

11 6 4
34,950 points

Related questions

1 vote
1 answer 28 views
28 views
Problem: I am starting writing code in python. I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote the following code: if 'key1' in dict.keys(): print "Present" else: print "Thanks" If there any other way to check this, please let me know.
asked Mar 10, 2020 Gavin 15.3k points
0 votes
1 answer 10 views
10 views
Problem: I have been learning C# and got an assignment in which I have to read a string as input from a user and then check if it contains a digit or not. If it contains a digit, a bool variable must be set to true, or else it must remain false. After this, a validity ... of the bool variable. I have no idea how I can do this task. If any of you could help, that would be a great pleasure. Thanks!
asked Nov 30, 2020 Code Learner 5.5k points
0 votes
1 answer 26 views
26 views
Problem Hi Kodlogs, How do I check if a file exists in python? Need help please.
asked Nov 3, 2020 hashq 1.1k points
0 votes
1 answer 21 views
21 views
How do I loop over python list with variables ?
asked Oct 28, 2020 psandprop 2.4k points
0 votes
1 answer 16 views
16 views asked Oct 29, 2020 john 580 points
1 vote
1 answer 43 views
43 views
Problem: I was trying to check if an element does exist in a list using a pyhton program: primary_list = [ 10, 12, 16, 6, 20, 33 ] a = input("Please enter a number to check if this exists in the list: ") print("Checking if input exists in this list : ") for ... not giving any output that is right. What should I do to fix this and how to check if an element does exist in a list. Thanks in advance.
asked May 16, 2020 samhaz 5k points
1 vote
1 answer 22 views
22 views
Problem: I tried to check if a string is a palindrome or not so I wrote this program in python: def Word(str): for i in range(0, len(str)/2): if str[i] != str[len(str)-i-1]: return False return True a = input("Enter a word to check:") ... TypeError: 'float' object cannot be interpreted as an integer What should I do now and how to check if a string is a palindrome or not using python program?
asked May 15, 2020 samhaz 5k points
1 vote
1 answer 31 views
31 views
Problem: I wrote a code to check if a number is even or odd in python. The program is in the snippet below: number = input("Please enter any number to check if it is even or odd: ") result = number % 2 if result == 0: print("The number ... 2 TypeError: not all arguments converted during string formatting Why this error message is appearing & what is the problem with my program? Thanks in advance.
asked May 13, 2020 samhaz 5k points
3 votes
1 answer 19 views
19 views
Problem: Hi all, I am trying to figure out the dictionary related problems in python. Dictionary is really fun to learn and work with. Let’s say, I have a dictionary dict = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'} If ... needed to check every value inside the dictionary what can I do for that? So, I want to know how to check if a value is in a dictionary python?
asked Mar 24, 2020 Gavin 15.3k points
0 votes
1 answer 25 views
25 views
How can i check if a number is even in python? I am new to programming and I was doing some practice. I wrote a code to check if a number is even in python: number = int(input("Please enter a number to check")) if (number % ) == 1 print("the number is even") but ... an error : File "main.py", line 2 if (number % ) == 1 ^ SyntaxError: invalid syntax can anyone help me out to sort out this problem?
asked Mar 14, 2020 LizzyM 6.1k points