Python study notes for Objective-C programmers
I don’t write Python often and I always forget its syntax. Therefore, I’m keeping a note of the major differences between Python and Objective-C that I’ve learnt here. Hope it helps you too!
Basics
Objective-C | Python |
---|---|
|| |
or |
&& |
and |
YES |
True |
NO |
False |
String
Objective-C | Python |
---|---|
string.length |
len(string) |
[string hasPrefix:prefix] |
string.startswith(prefix) |
[string hasSuffix:suffix] |
string.endswith(suffix) |
Comments
Objective-C
// comment
/*
multiline
comment
*/
Python
# comment
'''
multiline
comment
'''
str()
Objective-C
NSDictionary *dict = @{ @"Name": @"Zara", @"Age": @"7" };
NSLog("Description: %@", [dict description]);
Python
dict = {'Name': 'Zara', 'Age': 7};
print "Equivalent String : %s" % str (dict) # str()
Other
C / Objective-C
if (condition1){
}else if (condition2){
statement2;
}else {
statement3;
}
Python
if condition1: # note the colon
pass # use pass for an empty code block
elif condition2: # elif = else if
statement2
else: # don't forget the ':'
statement3